clicked event never fires

C

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
 
S

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
 
E

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.
 
C

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top