LinkButton added at runtime - and fetch it!

F

Fredrik Rodin

All,

I've been trying to get this question answered before and I got some hints,
but nothing that really fit my needs.

Here's what I'm aiming at:

I create x number of LinkButton at run-time in a UserControl, no probs.

However, when I click on on of them, I want to fetch which one of them that
was clicked and a value which is assigned via lnkbtn.ID (I could also take
the .text attribute, but I prefer the .ID).

Here is my simple sample code:

For a As Integer = 0 To 5

Dim lnkbtn As New LinkButton
lnkbtn.ID = "lnkbtn_" & CType(a, String)
lnkbtn.Text = "Linkbutton " & a

Me.Controls.Add(lnkbtn)

Next

So far so good. Now, how do I write a procedure that fetch the button
clicked? I want to get the text or the ID from that button.

I've been on Google, a number of forums and MSDN but can't find anything
that really explains this.

I'm writing everything in VB. One suggestion I got was to use a DataList,
but that doesn't really work for me.

Please note:
I DON'T add anything in design-time.

All help appreciated!

Thanks,
Fredrik
 
M

Mark Fitzpatrick

Instead of this approach, why not set this information as part of the
CommandText. You can then wire-up a Command event to catch this instead of
the Click event.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage
 

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

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top