Problem with wiring an event to a dynamic LinkButton

  • Thread starter Thread starter Bill
  • Start date Start date
B

Bill

I'm trying to dynamically build several linkbuttons and
wire them up to a method called OnLinkClick . . .

For the life of me, I don't understand why the code below
isn't firing the event.

LinkButton lbBC = new LinkButton();
phBreadCrumb.Controls.Add(lbBC);
lbBC.Font.Size = 11;
lbBC.CssClass = "lnkBtnBreadCrumbProperties";
lbBC.Text = aryHyperlinks;
lbBC.ID = "lbBC" + i.ToString();
lbBC.CommandArgument = aryHyperlinks;
lbBC.Command += new
System.Web.UI.WebControls.CommandEventHandler
(OnLinkClick);



private void OnLinkClick(object O,
System.Web.UI.WebControls.CommandEventArgs E)
{
lblErrorMsg.Text = "Testing";
}
 
Hi Bill,

Thanks for posting in this group.
To dynamic add control to the web form in Asp.Net, you should add the
control to the form which uses runat="server".
To get the programmatic access to the HTML <form> element on the server,
you should declare a variable for the existing form element in the .aspx
file.
For a step by step tutorial, please refer to:
http://support.microsoft.com/?id=317794

And I have tried the linkbutton's command event through this way, it works
well.
If you have anything unclear, please feel free to tell me.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top