473,413 Members | 1,778 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

Firing events from child controls in a Web Custom Control

Hey guys,

I am working on a web custom control that basically draws a table (ASP
Table) with a few child controls in the cells.

I have a command button inside one of these cells. The problem I am running
into is that I cannot get the click event of this object handled. I have
tried wiring the event with "AddHandler" among other things and that seems
not to work neither.

At this point I am completely stuck and ran out of ideas. Does anyone know
how to accomplish this?

Here is the code:

.......
.......
Public WithEvents oSubmit As New WebControls.Button
.....
.......
Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter)
oTable.Rows.Clear()
......
.........
oRow = New WebControls.TableRow
'Setup submit button cell
oCell = New WebControls.TableCell
'Add button to cell
oCell.Controls.Add(oSubmit)
'Add cell to Row
oRow.Cells.Add(oCell)
'Add Row to table
oTable.Rows.Add(oRow)
oTable.RenderControl(output)

End Sub
=============================

As you can see up there, the button is added dynamically to the cell. When I
run the page, the button simply does not generate a click event. Here is the
code for the click event:

Private Sub oSubmit_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles oSubmit.Click
........
..............
End Sub

This never fires. Does anyone know why???

Thanks!
Nov 18 '05 #1
2 2198
because you create the control at Render time, which comes long after event
handling, it doesn't exist when the event is triggered. you need move your
control creation to CreateChildControls, implement IPostBackEventHandler, so
you can forward the click, and call EnsureChildControls by onload (so that
the control exists to recieve the event).
-- bruce (sqlwork.com)


"Juan Romero" <ju*********@bowne.com> wrote in message
news:Od*************@TK2MSFTNGP12.phx.gbl...
Hey guys,

I am working on a web custom control that basically draws a table (ASP
Table) with a few child controls in the cells.

I have a command button inside one of these cells. The problem I am running into is that I cannot get the click event of this object handled. I have
tried wiring the event with "AddHandler" among other things and that seems
not to work neither.

At this point I am completely stuck and ran out of ideas. Does anyone know
how to accomplish this?

Here is the code:

......
......
Public WithEvents oSubmit As New WebControls.Button
....
......
Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter) oTable.Rows.Clear()
.....
........
oRow = New WebControls.TableRow
'Setup submit button cell
oCell = New WebControls.TableCell
'Add button to cell
oCell.Controls.Add(oSubmit)
'Add cell to Row
oRow.Cells.Add(oCell)
'Add Row to table
oTable.Rows.Add(oRow)
oTable.RenderControl(output)

End Sub
=============================

As you can see up there, the button is added dynamically to the cell. When I run the page, the button simply does not generate a click event. Here is the code for the click event:

Private Sub oSubmit_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles oSubmit.Click
........
..............
End Sub

This never fires. Does anyone know why???

Thanks!

Nov 18 '05 #2
I have found the solution to my problem. I am posting it here in case
someone else is having problems with this:

A composite control must do the following:

- Override the protected CreateChildControls method inherited from Control
to create instances of the child controls and add them to its Controls
collection.
- Implement the System.Web.UI.INamingContainer interface. INamingContainer
is a marker interface that has no methods. When a control implements
INamingContainer, the ASP.NET page framework creates a new naming scope
under that control, thus ensuring that the child controls have unique names
in the hierarchical tree of controls. This is especially important when a
composite control exposes template properties, provides data binding, or
needs to route events to its child controls.

You do not have to override the Render method because child controls provide
the rendering logic. Note that you can bubble events from the child controls
up to the container and expose them as top-level events on the container.

"Juan Romero" <ju*********@bowne.com> wrote in message
news:Od*************@TK2MSFTNGP12.phx.gbl...
Hey guys,

I am working on a web custom control that basically draws a table (ASP
Table) with a few child controls in the cells.

I have a command button inside one of these cells. The problem I am running into is that I cannot get the click event of this object handled. I have
tried wiring the event with "AddHandler" among other things and that seems
not to work neither.

At this point I am completely stuck and ran out of ideas. Does anyone know
how to accomplish this?

Here is the code:

......
......
Public WithEvents oSubmit As New WebControls.Button
....
......
Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter) oTable.Rows.Clear()
.....
........
oRow = New WebControls.TableRow
'Setup submit button cell
oCell = New WebControls.TableCell
'Add button to cell
oCell.Controls.Add(oSubmit)
'Add cell to Row
oRow.Cells.Add(oCell)
'Add Row to table
oTable.Rows.Add(oRow)
oTable.RenderControl(output)

End Sub
=============================

As you can see up there, the button is added dynamically to the cell. When I run the page, the button simply does not generate a click event. Here is the code for the click event:

Private Sub oSubmit_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles oSubmit.Click
........
..............
End Sub

This never fires. Does anyone know why???

Thanks!

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Kenton Smeltzer | last post by:
Hello All, I am having a problem with events and the addition of controls on a page I am developing. First let me tell you what I have tried and then maybe someone can see something I missed. ...
3
by: Tim Thomas | last post by:
Hi, I am very new to .NET and am in the process of building my first web application. I will briefly describe what i am trying to achieve: I have a system where suppliers register their...
1
by: Shourie | last post by:
I've noticed that none of the child controls events are firing for the first time from the dynamic user control. Here is the event cycle. 1) MainPage_load 2) User control1_Load user clicks a...
2
by: Juan Romero | last post by:
Hey guys, I am working on a web custom control that basically draws a table (ASP Table) with a few child controls in the cells. I have a command button inside one of these cells. The problem I...
3
by: Mike | last post by:
Hi, I am adding controls dynamically in a WebForm, but none of these controls' events fire. Here is the class code I am using. I have tried so many things, but nothing works :-( namespace...
5
by: bryanp10 | last post by:
I have a page that is almost entirely dynamically created. Textboxes and checkbox are working fine, firing events, and persistent their state. DropDownList is giving me a major headache. All...
10
by: Wylbur via DotNetMonster.com | last post by:
Hello to all of you geniuses, I'm having a problem trying to get an Init handler to fire for a Placeholder control at the initialization phase. I’ve posted this problem to 3 other ASP.NET...
12
by: scsharma | last post by:
Hi, I am working on creating a webapplication and my design calls for creating main webform which will have menu bar on left hand side and a IFrame which will contain all the forms that are shown...
1
by: mpaine | last post by:
I have read http://msdn2.microsoft.com/en-us/library/ms178472(VS.80).aspx and my interpretation is that custom events should be fired between Page_Load and Page_LoadComplete. When I run the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.