By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,440 Members | 1,872 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,440 IT Pros & Developers. It's quick & easy.

Click on LinkButton does not trigger custom handler associated with that LinkButton

P: 10
I have added a LinkButton to a table cell programmatically inside the Page_Load method. I also added a custom event to that link button. The same custom event is valid for all the link buttons. The table gets successfully displayed on the browser with the LinkButton. When I click on the link button in the browser, my control does not go inside the custom even that I wrote for the link button.

I have a table control as ProviderTbl in which multiple LinkButton gets displayes (one linkButton in each row) because of the Page_Load method. Obviously, all the LinkButtons have the same custom event handler called ClickHandler.
My goal is, when I click on one of the link buttons (from one of the rows of the table), I want to go to the custom ClickHandler that I have written. I want to eventually find out the ID, commad argument etc. of the link button being clicked on the server side.

However, when I click on the LinkButton, I get the control back to the else condition of Page_Load. Control never goes to the custom ClickHandler method that I thought it would go to, when clicked on the LinkButton.

C# Code is as follows:

#
public partial class SelectedProvider : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
for (int i = 0; i < providersList.Count; i++)
{
MyProvider provider = (MyProvider)providersList[i];
TableRow r = new TableRow();
CellID = new TableCell();
LinkButton LB = new LinkButton();
LB.ID = provider.GetID();
LB.Text = provider.GetID();
LB.CommandName = provider.GetID();
LB.CommandArgument = provider.GetID();
LB.Click += new System.EventHandler(LinkButton_ClickHandler);
CellID.Controls.Add(LB);
r.Cells.Add(CellID);
ProviderTbl.Rows.Add(r);
}
}
else
{
}

}

protected void LinkButton_ClickHandler(object sender, EventArgs e)
{
LinkButton linkButton = (LinkButton)sender;
string s1 = linkButton.ID;
}
}
#
Dec 8 '06 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.