Reputation: 3245
I have two UpdatePanel in my Web-form . Both UpdateMode="Conditional"
. An asynchronous trigger in UpdatePanel1 fire UpdatePanel2.Update()
event.
I would like in UpdatePanel2 whenever his update() method is fired , Do some stuff (like loading some user-control dynamically based on some criteria ).
How can I do that ?
Edit :
This is simplified version of my needs . UpdatePanel2.Update() method could fired from every where like MasterPage and ... . doing some stuff
is not just loading user-control
Upvotes: 1
Views: 4146
Reputation: 22478
Check this answer: How to know which UpdatePanel causes the partial PostBack?
Also you can use such approach without implementing own UpdatePanel control inherited from existing one with reflection:
private static PropertyInfo RequiresUpdateProperty;
protected void Page_Init(object sender, EventArgs e)
{
RequiresUpdateProperty = RequiresUpdateProperty?? typeof(UpdatePanel).GetProperty("RequiresUpdate", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
}
protected void Page_PreRender(object sender, EventArgs e)
{
if ((bool)RequiresUpdateProperty.GetValue(UpdatePanel2, null))
{
// gotcha!
}
}
Be warned that the RequiresUpdate proeprty returns false when you set Conditional UpdateMode and postback caused by UpdatePanel's child control which isn't added to Triggers collection.
P.S. code above requires FullTrust code access security level since it use reflection
Upvotes: 1
Reputation: 11125
Well you already answered your question. It is you who will decide when the updatepanel2 will update so it will be you specifying the code to add controls dynamically. As for the event, framework does not provide a event that launches for each updatepanel update :).
UpdatePanel2.Update();
since you called update before this statement you will add all your controls like below
TextBox tbox = new TextBox();
tBox.ID = "txtbox1";
UpdatePanel2.Controls.Add(tBox);
UpdatePanel2.Update();
Upvotes: 0