I have an aspx page that has a control which serves as a summary for a GridView that is on the same page. When the page loads, it creates the summary control and dynamically creates links and attaches an event handler to it. Here is a snippet:
protected void Page_Load(object sender, EventArgs e)
{
LoadSummaries();
}
LoadSummaries() loops through the DataSet for the GridView and creates the links. Here is a snippet of how I am creating the links and attaching and event handler to them:
LinkButton lb = new LinkButton();
lb.Text = "Dynamic Text goes here";
lb.Click += new System.EventHandler(this.Search);
lb.CommandName = "CommandName";
lb.CommandArgument = "CommandArgument";
When I run the page, it loads everything fine, but I need to click the link twice for it to go into to Search method. On the first click, the page reloads, but it doesn't go into the search method. On the second click, it does go into the search method.
I was curious as to if it was because on the first click, it actually binds the event handler to the linkbutton, but this is happening in Page_Load, so when the page is loaded, LoadSummaries is called which in turn binds the events to the link button, so I am stuck on understanding why I need to click it twice.