UpdatePanelUpdateMode3CS.aspx 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <%@ Page Language="C#" %>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <script runat="server">
  4. protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
  5. {
  6. switch (DropDownList1.SelectedValue)
  7. {
  8. case "1":
  9. UpdatePanel1.Update();
  10. break;
  11. case "2":
  12. UpdatePanel2.Update();
  13. break;
  14. case "3":
  15. UpdatePanel1.Update();
  16. UpdatePanel2.Update();
  17. break;
  18. }
  19. DropDownList1.SelectedIndex = 0;
  20. }
  21. protected void Page_Load(object sender, EventArgs e)
  22. {
  23. ScriptManager1.RegisterAsyncPostBackControl(DropDownList1);
  24. }
  25. </script>
  26. <html xmlns="http://www.w3.org/1999/xhtml">
  27. <head id="Head1" runat="server">
  28. <title>UpdatePanelUpdateMode Example</title>
  29. </head>
  30. <body>
  31. <form id="form1" runat="server">
  32. <div>
  33. <asp:ScriptManager ID="ScriptManager1"
  34. runat="server" />
  35. <asp:Panel ID="Panel1"
  36. GroupingText="Panel 1"
  37. runat="server">
  38. <asp:UpdatePanel ID="UpdatePanel1"
  39. UpdateMode="Conditional"
  40. runat="server">
  41. <ContentTemplate>
  42. <p>
  43. UpdatePanel.Update() method is called if this panel is selected
  44. to be updated from DropDownList control. Last updated:
  45. <%= DateTime.Now.ToString()%>
  46. </p>
  47. </ContentTemplate>
  48. </asp:UpdatePanel>
  49. </asp:Panel>
  50. <asp:Panel ID="Panel2"
  51. GroupingText="Panel 2"
  52. runat="server">
  53. <asp:UpdatePanel ID="UpdatePanel2"
  54. UpdateMode="Conditional"
  55. runat="server">
  56. <ContentTemplate>
  57. <p>
  58. UpdatePanel.Update() method is called if this panel is selected
  59. to be updated from DropDownList control. Last updated:
  60. <%= DateTime.Now.ToString() %>
  61. </p>
  62. </ContentTemplate>
  63. </asp:UpdatePanel>
  64. </asp:Panel>
  65. <asp:DropDownList ID="DropDownList1"
  66. AutoPostBack="True"
  67. OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"
  68. runat="server">
  69. <asp:ListItem Text="Select a panel to update..."
  70. Value="0"
  71. Selected="True" />
  72. <asp:ListItem Text="Refresh Panel 1"
  73. Value="1" />
  74. <asp:ListItem Text="Refresh Panel 2"
  75. Value="2" />
  76. <asp:ListItem Text="Refresh Panel 1 + 2"
  77. Value="3" />
  78. </asp:DropDownList>
  79. </div>
  80. </form>
  81. </body>
  82. </html>