Home All Groups Group Topic Archive Search About
Author
4 Apr 2006 2:37 PM
chambersdon
I have a webControl that extends the dataGrid with a button added.
When this butotn is clicked I don't get the clicked event.  I've
removed almost all the code and I'm down to a very basic example.

I've made similar controls in the past and have never had this problem.
In fact, the code below is almost an exact copy of code that works
when extending a textBox.  I'm probably over looking something very
simple.

Here is my class:

Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls
<DefaultProperty("Text"), ToolboxData("<{0}:AutoDataGrid
runat=server></{0}:AutoDataGrid>")> Public Class AutoDataGrid
    Inherits System.Web.UI.WebControls.DataGrid
    Protected WithEvents someBtn As
System.Web.UI.WebControls.ImageButton


    Protected Overrides Sub CreateChildControls()
        someBtn = New ImageButton
        Me.Controls.Add(someBtn)
    End Sub

    Protected Overrides Sub Render(ByVal writer As
System.Web.UI.HtmlTextWriter)
        ensurechildcontrols()
        someBtn.RenderControl(writer)
        MyBase.Render(writer)
    End Sub

    Private Sub someBtn_Click(ByVal sender As Object, ByVal e As
System.Web.UI.ImageClickEventArgs) Handles someBtn.Click
        Dim i As Integer
        i = 5
    End Sub
End Class

Author
5 Apr 2006 1:02 AM
sam
in this code i don't see where you hook up the evetn.
Author
5 Apr 2006 5:32 AM
srinivas
Please check this someBtn_Click event registered or not in system generated
code. some times these events can be missed. so that, it won't identify this
event. Please check once and let me know.

Thanks
Dotnetsrini
Author
5 Apr 2006 6:50 PM
Elroyskimms
Try using the AddHandler method after you declare each instance of
someBtn and before you add that instance to the parent control.

Your code looks correct for an image button that is already declared in
HTML but not for an image button that is dynamically created and added.
Author
6 Apr 2006 2:58 PM
chambersdon
I've tried all the suggestions I have gotten so far before I posted the
question.  I've done a little more research and it seems that there are
problems with adding Controls to a Control inherited from DataGrid.

The suggestions I've seen suggest that I inherit from WebControl but
then I can't use the DataGrid property builder at design time.