Dynamic linkbutton event doesn't fire

G

Guest

Hi,

I have linkbuttons created dynamically and they display fine on the web
page. However, when I click on the those link buttons, the event doesn't fire.

Please tell me what's wrong with the following code. Thanks.

Dim lbtnQuestion As LinkButton = New LinkButton
lbtnQuestion.Text = "Question " & (j + 1).ToString()

lbtnQuestion.CommandArgument = j
AddHandler lbtnQuestion.Command, AddressOf lbtnQuestion_Click

........................................................................................
Private Sub lbtnQuestion_Click(ByVal sender As Object, ByVal e As
CommandEventArgs)

Response.Write("Hey")

End Sub
 
G

Guest

I tested ur code.
It works for me !!

post the complete code, see if u are checking ispostback ??
Because dyanmic controls needs to created on load everytime.
 
G

Guest

Hi vinay,

Thank you for replying.

I have these linkbuttons created on certain occasions only, not always, so I
can't have them in ispostback or init. In most cases when the page is
postback, it should display something else, Only when this particular button
is clicked then the linkbuttons are created. All I want is when one of these
linkbuttons is clicked on, it redirects to a another page. Hmmm but you're
right, first comes the postback then comes the event, and the linkbutton is
gone during postback. I don't know how to deal with this.
 

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

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top