Wednesday, March 21, 2012

Question about: A demonstration of ASP.NET AJAX

I have just whatchedA demonstration of ASP.NET AJAX @dotnet.itags.org. http://ajax.asp.net/

and i notice that during the demon the demonstrator creates two update pannels the one containing the data list the other containing the insert record control, what is not clear from this demo is weather the it is posible to update the datalist now that the insert record control is in a seperate update panel, as no extra triggers were added to the data list. Being a synic i wondered if the demonstrator had deiberatley paged the data list and added extra items to it before the update pannels were introduced so that when he added the extra record via the control in the update pannel it would be added to the end of the list, which was on the secound page which could only be viewed when the user selected to view the secound page forcing the datalist update panel to be refreshed. So i was left wondering if this was to hide a limmitation of the technology and weather it was posible to add a asychronus post back triger based on the event that is within a seperate update pannel.

Q. Is it posible to add a asychronus post back triger, in one update pannel based on the event of a control in a diferent (sibling) update pannel, is that control visible from the other update pannel?

ps Any change of a spell check for this interface, i think i could use oneWink

The answer is yes. Here is a simple example:

1<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">2 <ContentTemplate>3 <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true">4 <asp:ListItem Text="CA" Value="CA" />5 <asp:ListItem Text="CO" Value="CO" />6 <asp:ListItem Text="FL" Value="FL" />7 </asp:DropDownList>8 </ContentTemplate>9</asp:UpdatePanel>1011<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">12 <ContentTemplate>13 Last Update:<%= DateTime.Now.ToLongTimeString()%>14 </ContentTemplate>15 <Triggers>16 <asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" />17 </Triggers>18</asp:UpdatePanel>

In line number 16 you can see that a trigger is registered for a control that reside within a different UpdatePanel. Also, programmatically you can also call the Update() method on any UpdatePanel that has it's UpdateMode set to Conditional.

No comments:

Post a Comment