I'm trying to speed up the load time of an asp page. A method used by one small ui component takes up about 80% of the load time, and so I've delegated this to a separate thread which is queried by an ajax call every second in order to display the component when it's ready whilst maintaining the functionality of the rest of the page.
Once the background thread has finished, the component is created as part of the ajax call. The component is a collapsible list of links, each of which needs to perform a postback to load up a new page. As these links are created after the page has loaded I can't simply assign event handlers to the click events of each one, and so I've created a hidden button (behindTargetLinkButton) with the click handler assigned to it such that the href for the hidden button looks like this;
javascript:__doPostBack('moduleHome$Home$behindTargetLinkButton','')
I then set the href of each link to the following, where args is a string containing information unique to each link.
javascript:__doPostBack('moduleHome$Home$behindTargetLinkButton','" + args + "')
When I debug server side and put a breakpoint in the handler method, I hit it when clicking on the hidden button directly (making it visible for testing purposes), but not when clicking on one of the links, even though the two hrefs are identical. Debugging client side, they both correctly hit the __doPostBack function and both submit the form correctly with the same eventTarget and so I don't understand why the hidden button is correctly posting back to the server, but the individual links are not. I've also tried to do this without posting back any arguments with the latter such that the hrefs are completely identical, but this makes no difference. Could anybody shine some light on to why this is happening, and perhaps offer a solution to the problem?
The ajax call returns a string containing the html for the component to place inside an existing placeholder div ("toggle").
StringWriter sw = new StringWriter();
HtmlTextWriter h = new HtmlTextWriter(sw);
toggle.RenderControl(h);
string str = sw.GetStringBuilder().ToString();
The individual links are created with the following, and added to the toggle div in a foreach loop;
HtmlGenericControl li = new HtmlGenericControl("li");
LinkButton a = new LinkButton();
a.Attributes["href"] = "javascript:__doPostBack('moduleHome$Home$behindTargetLinkButton','" + args + "')";
li.Controls.Add(a);
The hidden button is created in the aspx page in html;
<asp:LinkButton ID="behindTargetLinkButton" runat="server" Style="display: none;" />
And then the click handler is added in the OnInit method of my code behind.
behindTargetLinkButton.Attributes["link"] = "behindTarget_Edit";
behindTargetLinkButton.Click += new EventHandler(notification_Click);
The click handler is used for all the buttons on the page and has a switch statement on the link attribute to decide which code to run;
protected void notification_Click(object source, EventArgs e)
{
LinkButton a = (LinkButton)source;
ModuleAction act;
switch (a.Attributes["link"].ToString())
{
case "behindTarget_Edit":
// Code to create an action to take you to the relevant page
break;
}
}
Thanks.