473,398 Members | 2,088 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,398 software developers and data experts.

Control added at runtime not raising events.

Hi all,

I am dynamically adding a link button to a page, but for some reason it is
not raising the click event in the code behind. Here are some snippets from
my code -- any help is greatly appreciated:

' declaring variable
Protected WithEvents lbtEquipment As
System.Web.UI.WebControls.LinkButton

...

' setting properties
lbtEquipment = New System.Web.UI.WebControls.LinkButton
lbtEquipment.Text = "New"
lbtEquipment.ID = "lbtEquipment"
lbtEquipment.CssClass = "GridDataEntryNew"

' adding control to table cell
tcNew.Controls.Add(lbtFreeboard)

...

' trying to handle the click event
Private Sub lbtEquipment_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles lbtEquipment.Click
Try
Response.Write("test")

Catch ex As Exception
End Try
End Sub

I know this is a bit out of context, but hopefully someone can tell me what
I'm missing. I want the linkbutton, which was added to the table cell, to
raise the lbtEquipment_Click event when it's clicked!

Thanks!

Wade
Nov 18 '05 #1
1 1269
You need to make sure lbtEquipment is created on postback and that this
happens before the certain events (LoadViewStateSecondTry I think is the
event in question)...this typically means the control must be recreated on
Page_Load.

My guess is that you aren't doing one of those two things...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Wade" <wwegner23NOEMAILhotmail.com> wrote in message
news:O0**************@TK2MSFTNGP09.phx.gbl...
Hi all,

I am dynamically adding a link button to a page, but for some reason it is
not raising the click event in the code behind. Here are some snippets from my code -- any help is greatly appreciated:

' declaring variable
Protected WithEvents lbtEquipment As
System.Web.UI.WebControls.LinkButton

...

' setting properties
lbtEquipment = New System.Web.UI.WebControls.LinkButton
lbtEquipment.Text = "New"
lbtEquipment.ID = "lbtEquipment"
lbtEquipment.CssClass = "GridDataEntryNew"

' adding control to table cell
tcNew.Controls.Add(lbtFreeboard)

...

' trying to handle the click event
Private Sub lbtEquipment_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles lbtEquipment.Click
Try
Response.Write("test")

Catch ex As Exception
End Try
End Sub

I know this is a bit out of context, but hopefully someone can tell me what I'm missing. I want the linkbutton, which was added to the table cell, to
raise the lbtEquipment_Click event when it's clicked!

Thanks!

Wade

Nov 18 '05 #2

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

Similar topics

7
by: Colin Young | last post by:
I have a UserControl that contains a calendar control. The calendar is not raising events (month navigation, date selections, etc.). I've checked that the OnSelectionChanged event has a handler...
0
by: Greg Park | last post by:
I have many user controls loading into a web page using Page.LoadControl However, I'm unable to figure out how to raise an event when a button is click or a check box is checked. I can have...
5
by: karthick raja | last post by:
Am experiencing a problem intercepting the events from controls added dynamically to a Placeholder control at runtime. Is there any way that I can write an event handler on the page which will be...
4
by: thomson | last post by:
Hi all, i do have a user control with 4 buttons, and all the events are firing properly, My problem is that i need to right an event handler in the user control, which gets fired after a...
7
by: Shimon Sim | last post by:
I have a custom composite control I have following property
9
by: Charles Law | last post by:
I have a form on which user controls are placed at runtime. When a control is added to the form a handler is added for an event that a high-level object raises, which must be handled by the new...
5
by: Paul Bromley | last post by:
For some time now I have been struggling trying to understand how to handle events originating in a User Control that I have designed when using this in an application. Basically I need to respond...
2
by: Mike | last post by:
Hi, I am strugling with a simple problem which I can't seem to resolve. I have an asp.net page which contains a server-control (flytreeview, which is a kind of a tree to be exact). The tree is...
7
by: Christian Cambier | last post by:
Hi, I have a textbox in a web user control. I then add the usercontrol to a web form. I also add a label in the web form. Now, when I press a key in the textbox, i want to display some text...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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...

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.