Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Dynamically add linkbuttons and wire them to same event??

Reply
Thread Tools

Dynamically add linkbuttons and wire them to same event??

 
 
Linda
Guest
Posts: n/a
 
      04-28-2004
Hi,

How do I dynamically add linkbuttons and wire them to same event? I am able to add linkbuttons but they do not fire the event. Does anybody have a working sample?



Many thanks,

Linda


 
Reply With Quote
 
 
 
 
Victor Garcia Aprea [MVP]
Guest
Posts: n/a
 
      04-28-2004
Hi Linda,

If their events are not firing then I'm guessing you may be adding them too late in the execution lifecycle. At which point are you adding them? Also any short sample code you could provide will greatly help the guessing game.

--
Victor Garcia Aprea
Microsoft MVP | ASP.NET
Looking for insights on ASP.NET? Read my blog:
http://obies.com/vga/blog.aspx

To contact me remove 'NOSPAM'. Please post all questions to the newsgroup
"Linda" <(E-Mail Removed)> wrote in message news:%(E-Mail Removed)...
Hi,

How do I dynamically add linkbuttons and wire them to same event? I am able to add linkbuttons but they do not fire the event. Does anybody have a working sample?



Many thanks,

Linda


 
Reply With Quote
 
 
 
 
Robert Verderber
Guest
Posts: n/a
 
      04-28-2004
Linda,

You have to add an event handler to the control that you added
dynamically. For the below example code I created a new ASP.NET
project and placed a PlaceHolder control on the form.

In the Page_Load event place the following code:

'Instance a link button
Dim MyLinkButton As New LinkButton

'Set the text
MyLinkButton.Text = "Click Here for Google"

'Dynamically add to Place Holder
PlaceHolder1.Controls.Add(MyLinkButton)

'Add an event handler to button
AddHandler MyLinkButton.Click, AddressOf HandleMyLinkButtonClick


Then create a sub (delagate) to handle the click. It must have the
parameters as in the example. This example redirects to Google.

Sub HandleMyLinkButtonClick(ByVal sender As Object, ByVal e As
System.EventArgs)
Response.Redirect("http://www.google.com")
End Sub


If you have multiple links pointing to the same Handler you could use
something like the following to determine which link was clicked:

SelectedItemText = CType(sender, LinkButton).Text


Hope that helps.


On Tue, 27 Apr 2004 17:35:10 -0700, "Linda" <(E-Mail Removed)>
wrote:

>Hi,
>
>How do I dynamically add linkbuttons and wire them to same event? I am able to add linkbuttons but they do not fire the event. Does anybody have a working sample?
>
>
>
>Many thanks,
>
>Linda


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
can we dynamically create custom controls and then add them into catalog zone? rifat yavuz ASP .Net Web Controls 0 07-04-2008 02:58 PM
Handling Onclick Event from dynamically created linkbuttons (1.1) RSH ASP .Net 1 04-23-2007 02:43 PM
DMA 40-pin/80-Wire with a empty spot on one wire? lcs A+ Certification 1 02-02-2006 09:06 AM
2 Wire and 3 Wire Telecom Wiring SchoolTech NZ Computing 1 02-26-2005 08:23 AM
Dynamically added Templated Columns (Implementing ITemplate) in DataGrid - How do I wire up events? David ASP .Net Datagrid Control 5 02-18-2004 08:28 AM



Advertisments