I have a form with an update panel, inside of the update panel is a div runat=”server”. I am dynamically adding user controls to this div. Inside of the user control is a link button. I would like to raise a Click event on this link button. I know that I must add the trigger dynamically as well. I am attempting to do this on the user control’s ‘Page_Load’ event using reflexion.
//Inside User Control
protected void Page_Load(object sender, EventArgs e)
{
this.Page.GetType().InvokeMember("AddTrigger", System.Reflection.BindingFlags.InvokeMethod, null, this.Page, new object[] { this.lbDetails.UniqueID, "Click"});
}
//On the page
public void AddTrigger(string controlId, string eventName)
{
AsyncPostBackTrigger trigger = new AsyncPostBackTrigger();
trigger.ControlID = controlId;
trigger.EventName = eventName;
this.upContent.Triggers.Add(trigger);
}
This appears to be happening correctly, I can see the update panel triggers collection having the new trigger. Although, the trigger control name attribute does have the user control name as a prefix.. I am passing the uniqueId as the control name attribute for the async trigger (e.g. ctl11$lbDetails)… The Event is just ‘Click’. This does not appear to be working. When I click the linkButton the event handler method is not firing..
Thanks in Advance guys??
Ok, I found a work around which does not involve using triggers or the scriptManager registry.
This is the page
This is the page code behind
This is the user control
This is the user control code behind