Problem with Dynamically Creating Link Buttons

B

Burak

Hello,

This is my code behind code for dynamic link button creation:

strUrl = "<asp:LinkButton CommandName='Onet3_Cd'
onfiltered='LinkButton_Command' runat='server' " & _
"Text='" & rdrOnet3("ONET3_TITLE") & "'
CommandArgument='" & rdrOnet3("ONET3_CD") & "' id='lb"
& i & "'></asp:LinkButton>"

Dim ctrl As Control =
Page.ParseControl(strUrl.ToString())
plcCategory.Controls.Add(ctrl) ' place holder on html page

The link button shows up fine when I run this, but
when I click on the link, it doesn't take me to

Sub LinkButton_Command(ByVal sender As Object, ByVal e
As CommandEventArgs)

Dim strDesc As String
strDesc = sender.text
Response.Write(sender.text)
End Sub

I based my code on

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlr\
fsystemwebuiwebcontrolslinkbuttonclasscommandnametopic.asp

The click works if I hard code the link button on the
html page, but if I create it dynamically, the click
does not take me to the above sub.

Do you know how to fix this?

Thanks,

Burak
 
B

BK

Burak,
From what I understand, since you are creating the
imagebutton dynamically you have to make sure that you add
the imagebutton on every page load for your button_click
event to work.So make sure what ever code you are adding
to add the imagebutton dynamically is executed on every
page load.

Hope this helps
BK
 

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,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top