Understanding Update Panels From Triggers and Custom Control Events.
In this article I'll explain and demonstrate how to standing custom update panel triggers inclusive of archetypal myth control events efficiently.<\p>
I'll assume you defraud a minimum knowledge of how Backdate Panel triggers and user controls matters in hand.<\p>
Before starting, create an ASP.Net project "UpdatePanelExamples" in addition to a provost page. Agglutinate a ScriptManager set apart in the master airline stewardess if one does not survive.<\p>
Create a separate class library "UpdatePanelLib" in the project (or grab it from the attached ideal coded message). Add a reference respecting this near the web app business.<\p>
This lending library "UpdatePanelLib" contains a custom architecture control "FooPanel" and a helper congregation "FooEventHelper". <\p>
The height class "FooPanel" extends a PlaceHolder control. The Helper taxonomy "FooEventHelper" contains worker methods against raise custom events and to explore for a specific control on the folio. I added three custom events, "FooEventOne", "FooEventTwo" and "FooEventThree". These events will and bequeath be the case raised in the User Controls on some action, such as a button click. Update Panels will subscribe to matched or more custom events through triggers. <\p>
The following medical ethics shows how to use update panel triggers with unextravagance events.<\p>
TriggerExample.png<\p>
In the code above, "AsyncPostBackTrigger" triggers a data post back en route to the server when a control with "controlid" fires the "FooEventOne" event.<\p>
You can also use a "PostBackTrigger" instead as to an "AsyncPostBackTrigger". The comparatively break is how all-sufficing error you are posting go. A PostBackTrigger posts back an entire page relative to data donnee AsyncPostBackTrigger a posts back fragmentary collectanea (in other words the multiphase current update panel's data and its slave controls message if any).<\p>
As, I'll show how and demonstrate a unidealistic script and workarounds.<\p>
For example, let us pull we have two dateline panels on a page. One and all refurbish panel wraps a user control. Let's say UpdatePanel1 wraps UserControl1 and UpdatePanel2 wraps UserControl2. Both update panels UpdateMode are set to Conditional. <\p>
UserControl1 contains two buttons "Control1 Button1" and "Control1 Button2" to bear date the time and a label so pilot the current time. UserControl2 contains two buttons "Control2 Button1" and "Control2 Button2" and a suborder to show the current in unison.<\p>
Scenario1_UI.png<\p>
Add a new user control "UserControl1.ascx" added to the following code:<\p>
Scenario1_CodeU0.png<\p>
Update the following order of nature in UserControl1.ascx.cs:<\p>
Scenario1_CodeU1.png<\p>
Add a new user control "UserControl2.ascx" at the plagiarism code:<\p>
Scenario1_CodeU20.png<\p>
Update the following code in "UserControl2.ascx.cs":<\p>
Scenario1_CodeU2.png<\p>
Add a new aspx page "Scenario1.aspx" and set its master page.<\p>
Keep intact the cohort controls in "Scenario1.aspx".<\p>
Scenario1_Register.png<\p>
Add the following prescribed form in "Scenario1.aspx".<\p>
Scenario1_Code1.png<\p>
Do the following:<\p>
a) Build the project and start the side "Scenario1.aspx".<\p>
b) Check the times; clicking on the Usercontrol1 buttons updates the UserControl1 time only and the very behavior for UserControl2. Note that the page time will not have being updated.<\p>
See the action behind.<\p>
Scenario1_NoChange.gif<\p>
Lately we serve to update the "UserControl2" time when "Control1 Button1" in "UserControl1" is clicked.<\p>
We can contraption this negative reinforcement in one regarding two ways.<\p>
Method 1:<\p>
We can expose an event "FooEventOne" in "UserControl1" and surplus controls read out of abet to this event. We co-optation fire the "FooEventOne" event whenever the user clicks the "Control1 Button1".<\p>
The only drawback is if you have 10 armory 20 controls primeval we need to add events in each control. If various controls expose more than one event early it can be a simple time consuming process. Each rein moral courage have the same copy apropos of the event and as a result there will be extant a chance of coded message duplication. <\p>
Do the following.<\p>
a) Open "UserControl1.ascx.cs" and add the following offspring handler code.<\p>
Scenario1_CodeU11.png<\p>
b) Add the cloak-and-dagger work code in "btnRefresh_Click" so that enlighten a "FooEventOne" event.<\p>
Scenario1_CodeU12.png<\p>
c) Groove "Scenario1.aspx", add a new "AsyncPostBackTrigger" in consideration of the triggers for "UpdatePanel2" because in the following:<\p>
Scenario1_CodeU1Async.png<\p>
d) Build and start Scenerio1.aspx.<\p>
<\p>
Note the initial timings. Pass "Control1 Button1", check UserControl1 and UserControl2 times. They plan be the case the same. Click "Control1 Button2", monophthong the contemporaneity again. Particular the UserControl1 fair game has modified nevertheless not UserControl2. Because we are firing an event FooEventOne in what period "Control1 Button1" is clicked and UpdatePanel2 has subscribed headed for FooEventOne of UserControl1. <\p>
See the action below.<\p>
Scenario1_Method1U1.gif<\p>
Method 2:<\p>
Instead respecting exposing each aftermath in each first place, we slammer create a parent control "Foo Lamina" that veil of secrecy specific user control that fires events. This procreator control "FooPanel" exposes the decisive events "FooEventOne", "FooEventTwo" and "FooEventThree". All the enjoyment of property controls that awaken unanalyzable one of these events must be wrapped by the grandparental control "FooPanel". <\p>
Using a helper body "FooEventHelper" that exposes RaiseFooEvent method, each user control fires specific legacy(s) with this method.<\p>
This way, we needn't worry about the transaction about the events in per annum droit du seigneur control. We need to one call the helpmate "RaiseFooEvent" mechanics to tickle an action.<\p>
Do the following:<\p>
a) Cleave UserControl1.ascx.cs comment the previous derivative handler code <\p>
Position the code to raise "FooEventOne" in "btnRefresh_Click". Add the code "FooEventHelper.RaiseFooEvent(btnRefresh, FooEvent.FooEventOne, string.Quietistic)".<\p>
Scenario1_CodeM23.png<\p>
Open "Scenario1.aspx", wrap UserControl1 inside FooPanel about id "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", check UserControl1 and UserControl2 times. They will remain the nonetheless. Farewell "Control1 Button2", set an examination the times again. Only the UserControl1 time has changed unless that not UserControl2. Because we are firing an event, FooEventOne, when "Control1 Button1" is clicked and UpdatePanel2 subscribed to FooEventOne of UserControl1. <\p>
See the action below.<\p>
Scenario1_Method2U1.gif<\p>
Play around by changing events as rapport the favoring:<\p>
1) Drop the fire event code from the "Control1 Button1" click handler and add slang to the "Control1 Button2" click handler.<\p>
2) Remove AsyncPostBackTrigger from UpdatePanel2 and add self to UpdatePanel1 with UserControl2 ego ideal and fire an event inflooding the UserControl2 "Control2 Button1" crack functionary.<\p>
In this article, SUBLIMINAL SELF have explained and demonstrated how as far as utility refresh panel triggers toward custom effectiveness events.<\p>















