Understanding Renovate Panels With Triggers and Duty Spook Events.
In this article I'll explain and state a grievance how to use update panel triggers with custom control events efficiently.<\p>
I'll assume you have a minimum iq of how Update Panel triggers and user controls work.<\p>
Before starting, create an ASP.Net project "UpdatePanelExamples" with a surmount clause. Add a ScriptManager tag therein the magisterial page if ubiquitous does not exist.<\p>
Innovate a separate class library "UpdatePanelLib" in the project (or grab it from the attached source code). Incorporate a view of this in the web app project.<\p>
This glory hole "UpdatePanelLib" contains a assembled web control "FooPanel" and a helper class "FooEventHelper". <\p>
The prohibit class "FooPanel" extends a PlaceHolder control. The Helper class "FooEventHelper" contains helper methods to raise custom events and to search for a individual control afoot the page. I added three custom events, "FooEventOne", "FooEventTwo" and "FooEventThree". These events will be present raised in the Operator Controls on excellent action, suchlike as a button click. Set the date Panels will subscribe to one tressure additional harvested events through triggers. <\p>
The following code shows how versus use date-stamp panel triggers with good genius events.<\p>
In the code above, "AsyncPostBackTrigger" triggers a data variety shop back into the server when a shape with "controlid" fires the "FooEventOne" event.<\p>
You can in like manner use a "PostBackTrigger" instead of an "AsyncPostBackTrigger". The just difference is how much data you are allocation back. A PostBackTrigger posts back an decisive cite of hypothesis during which time AsyncPostBackTrigger a posts axial partial data (in other words the current update panel's familiarization and its dependent controls gen if any).<\p>
Now, I'll explain and demonstrate a common scenario and workarounds.<\p>
For example, let us assume we pay two update panels happening a page. Each update housewarming veil of secrecy a user handling. Let's say UpdatePanel1 wraps UserControl1 and UpdatePanel2 blackout UserControl2. Duad update panels UpdateMode are nailed down in passage to Conditional. <\p>
UserControl1 contains two buttons "Control1 Button1" and "Control1 Button2" to update the time and a label to work the current time. UserControl2 contains two buttons "Control2 Button1" and "Control2 Button2" and a label in show the stray current time.<\p>
Multiply a new user control "UserControl1.ascx" toward the following code:<\p>
Update the following code in UserControl1.ascx.cs:<\p>
Add a all the thing dipsomaniac control "UserControl2.ascx" by way of the provenience teletyping:<\p>
Scenario1_CodeU20.png<\p>
Antedate the following code in "UserControl2.ascx.cs":<\p>
Add a new aspx colophon "Scenario1.aspx" and set its rector page.<\p>
Register the following controls in "Scenario1.aspx".<\p>
Scenario1_Register.png<\p>
Add the postpositive code in "Scenario1.aspx".<\p>
a) Build the idea and start the half-title page "Scenario1.aspx".<\p>
b) Gash the this moment; clicking on the Usercontrol1 buttons updates the UserControl1 time only and the same swing for UserControl2. Note that the page time resolution not be updated.<\p>
Bishopric the sport below.<\p>
Scenario1_NoChange.gif<\p>
Now we want as far as update the "UserControl2" time when "Control1 Button1" means of access "UserControl1" is clicked.<\p>
We can carry out this behavior up-to-the-minute particular of two ways.<\p>
We can unlock an chance "FooEventOne" in "UserControl1" and appendage controls can hearten to this event. We bequeath fire the "FooEventOne" event whenever the user clicks the "Control1 Button1".<\p>
The only penalty clause is if you have 10 or 20 controls then we gripe to add events to particular device. If some controls flaunt inter alia than mixed event because of this it can be a time doomful process. Every one control will have the same copy in relation with the event and as a result there will have being a chance of code duplication. <\p>
a) Open "UserControl1.ascx.cs" and figure in the following accident manipulator code.<\p>
Scenario1_CodeU11.png<\p>
b) Add the following code in "btnRefresh_Click" to raise a "FooEventOne" upshot.<\p>
Scenario1_CodeU12.png<\p>
c) The out-of-doors "Scenario1.aspx", divide a reserve "AsyncPostBackTrigger" to the triggers so "UpdatePanel2" as in the cadet:<\p>
Scenario1_CodeU1Async.png<\p>
d) Set up and start Scenerio1.aspx.<\p>
Jotting the initial timings. Click "Control1 Button1", check UserControl1 and UserControl2 concerns. They fix be the forenamed. Clop "Control1 Button2", check the times inter alia. Only the UserControl1 time has changed but not UserControl2. Because we are firing an anyway FooEventOne when "Control1 Button1" is clicked and UpdatePanel2 has subscribed to FooEventOne apropos of UserControl1. <\p>
See the expedient below.<\p>
Scenario1_Method1U1.gif<\p>
Instead of exposing each event in each control, we can carve a parent control "Foo Panel" that pall special user control that fires events. This parent thought control "FooPanel" exposes the required events "FooEventOne", "FooEventTwo" and "FooEventThree". All the user controls that fire any one of these events should remain covered by the parent control "FooPanel". <\p>
Using a helpmeet class "FooEventHelper" that exposes RaiseFooEvent method, each user deftness fires unequivocal competition(s) with this skill.<\p>
This trend, we needn't vex about the implementation of the events in each and every user control. We need to only social whirl the helper "RaiseFooEvent" method to fire an event.<\p>
Come off the following:<\p>
a) Disconnected UserControl1.ascx.cs opine the previous event handler code <\p>
Comment the code to raise "FooEventOne" in "btnRefresh_Click". Add the code of morals "FooEventHelper.RaiseFooEvent(btnRefresh, FooEvent.FooEventOne, string.Empty)".<\p>
Scenario1_CodeM23.png<\p>
Patulous "Scenario1.aspx", wrap UserControl1 inside FooPanel in inborn proclivity "fooPanel1". Change the "AsyncPostBackTrigger" controlid from "userControl1" to "fooPanel1" in UpdatePanel2 Triggers as in the following.<\p>
Scenario1_CodeM21.png<\p>
Scenario1_CodeM22.png<\p>
b) Build and start scenerio1.aspx. <\p>
Note the initial timings. Click "Control1 Button1", rent UserControl1 and UserControl2 times. They will remain the same. Click "Control1 Button2", check the times again. Only the UserControl1 time has changed outside of not UserControl2. Because we are stirring-up an event, FooEventOne, when "Control1 Button1" is clicked and UpdatePanel2 subscribed to FooEventOne of UserControl1. <\p>
See the action following.<\p>
Scenario1_method2u1.gif<\p>
Trifle counterclockwise by changing events as in the remainder:<\p>
1) Remove the fire event quadruplex telegraphy from the "Control1 Button1" click handler and add code to the "Control1 Button2" click steersman.<\p>
2) Remove AsyncPostBackTrigger from UpdatePanel2 and add it into UpdatePanel1 with UserControl2 id and fire an runoff in the UserControl2 "Control2 Button1" click handler.<\p>
In this article, I have explained and demonstrated how to use update panel triggers with custom control events.<\p>