473,802 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.W ebControls.Link Button

...

' setting properties
lbtEquipment = New System.Web.UI.W ebControls.Link Button
lbtEquipment.Te xt = "New"
lbtEquipment.ID = "lbtEquipme nt"
lbtEquipment.Cs sClass = "GridDataEntryN ew"

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

...

' trying to handle the click event
Private Sub lbtEquipment_Cl ick(ByVal sender As Object, ByVal e As
System.EventArg s) Handles lbtEquipment.Cl ick
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_Cl ick event when it's clicked!

Thanks!

Wade
Nov 18 '05 #1
1 1285
You need to make sure lbtEquipment is created on postback and that this
happens before the certain events (LoadViewStateS econdTry I think is the
event in question)...thi s 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" <wwegner23NOEMA ILhotmail.com> wrote in message
news:O0******** ******@TK2MSFTN GP09.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.W ebControls.Link Button

...

' setting properties
lbtEquipment = New System.Web.UI.W ebControls.Link Button
lbtEquipment.Te xt = "New"
lbtEquipment.ID = "lbtEquipme nt"
lbtEquipment.Cs sClass = "GridDataEntryN ew"

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

...

' trying to handle the click event
Private Sub lbtEquipment_Cl ick(ByVal sender As Object, ByVal e As
System.EventArg s) Handles lbtEquipment.Cl ick
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_Cl ick 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
2697
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 being registered. Is there anything else obvious or otherwise that I've missed? Is there a problem using it in a UserControl? Thanks Colin
0
1724
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 upto a hundred user controls on a single page and AutoPostBack isn't an option. I have no problem with raising events when an user control is dropped on the aspx page.
5
1719
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 pick up the events raised by the added controls dynamically. I cannot use 'WithEvents' and 'Handles' because this requires that the controls be declared on the page and they aren't (they are created in the external class) I did think of using...
4
1756
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 specific process is done,, but the form which will host the user control has to specify what has to be done Something like this , if the event is fired it should call the event in
7
3021
by: Shimon Sim | last post by:
I have a custom composite control I have following property
9
20190
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 control. When I close the form I am expecting that the control ceases to be. However, if my object raises the event after the form has been closed, I find that there is still a user control object that handles it. Clearly the user control has not...
5
1402
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 to button clicks in my user control. I have struggled trying to understand Delegates, aqnd m still struggling. I then came across the following tutorial on MSDN and thought I had 'cracked it' ...
2
4928
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 being updated by some other process through remoting. When the page loads, I init the tree, and in my browser I can see the initialized tree. The problem is that every time that I receive update to tree from the remote process,
7
2876
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 in the label. I tried by raising events as used in Winforms but it is not as easy as
0
9699
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9562
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10538
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10305
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10063
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5494
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4270
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3792
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2966
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.