The first thing you want to do is always set your UpdatePanel’s UpdateMode to Conditional. By default UpdateMode is set to Always which is great when you’re first learning, but not efficient. Why? Because every time a postback is triggered, your update panel reloads, which 9 times out of 10, isn’t what you want.
The trick to setting up two different UpdatePanels is this. Lets say you have an UpdatePanel containing a GridView in one ContentPlaceHolder displaying a customer’s order history. You have another UpdatePanel in another ContentPlaceHolder that will display the order details when an order is selected.
The problem is you can’t declaratively set the Trigger to a control in a different ContentPlaceHolder.
What you need to do is override the OnInit() method.
Here is an example:
- protected override void OnInit(EventArgs e)
- {
- base.OnInit(e);
- AsyncPostBackTrigger trigger = new AsyncPostBackTrigger();
- trigger.ControlID = grdOrderList.UniqueID;
- trigger.EventName = "SelectedIndexChanged";
- updateDetails.Triggers.Add(trigger);
- }
Combine this with the UpdatePanelAnimation control to give a visual cue to the user that the data has been updated and you have a simple ajaxified solution.
- <ajaxtoolkit:updatepanelanimationextender
- id="upAnimation"
- behaviorid="upAnim"
- targetcontrolid="updateDetails"
- runat="server">
- <animations>
- <onupdating>
- <sequence>
- <color
- animationtarget="updateDetails"
- duration="1"
- startvalue="#ffffff"
- endvalue="#ffffcc"
- property="style"
- propertykey="backgroundColor">
- </color>
- </sequence>
- </onupdating>
- <onupdated>
- <sequence>
- <color
- animationtarget="updateDetails"
- duration="1"
- startvalue="#ffffcc"
- endvalue="#ffffff"
- property="style"
- propertykey="backgroundColor">
- </color>
- </sequence>
- </onupdated>
- </animations>
- </ajaxtoolkit:updatepanelanimationextender>
No comments:
Post a Comment