UpdatePanelHowTo1CS.aspx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <%@ Page Language="C#" %>
  2. <%@ Register Src="Controls/WebUserControl.ascx" TagName="WebUserControl" TagPrefix="uc1" %>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4. <script runat="server">
  5. protected void WebUserControl1_Click(object sender, EventArgs e)
  6. {
  7. if (WebUserControl1.Range != -1)
  8. Label1.Text = "You selected " + WebUserControl1.Range.ToString() + " day(s).";
  9. CalendarPanel.Visible = false;
  10. }
  11. protected void ShowCalendar(object sender, EventArgs e)
  12. {
  13. CalendarPanel.Visible = true;
  14. }
  15. protected void Page_Load(object sender, EventArgs e)
  16. {
  17. if (!IsPostBack)
  18. {
  19. CalendarPanel.Visible = false;
  20. Label1.Text = "You have not selected any days.";
  21. }
  22. }
  23. </script>
  24. <html xmlns="http://www.w3.org/1999/xhtml">
  25. <head runat="server">
  26. <title>UpdatePanel UserControl Example</title>
  27. <style type="text/css">
  28. div.CalendarPanel
  29. {
  30. background-color: white;
  31. text-align: center;
  32. position: absolute;
  33. top: 30px;
  34. left: 160px;
  35. width: 300px;
  36. }
  37. </style>
  38. </head>
  39. <body>
  40. <form id="form1" runat="server">
  41. <div>
  42. <asp:ScriptManager ID="TheScriptManager" runat="server" />
  43. <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
  44. <ContentTemplate>
  45. <asp:LinkButton ID="ShowCalendarLinkButton" runat="server" Text="Choose a number of days"
  46. OnClick="ShowCalendar" />
  47. <asp:Panel ID="CalendarPanel" GroupingText="Choose a Range" CssClass="CalendarPanel" runat="server">
  48. <uc1:WebUserControl ID="WebUserControl1" runat="server" OnInnerClick="WebUserControl1_Click">
  49. </uc1:WebUserControl>
  50. </asp:Panel>
  51. <br />
  52. <asp:Label ID="Label1" runat="server"></asp:Label>
  53. </ContentTemplate>
  54. </asp:UpdatePanel>
  55. </div>
  56. </form>
  57. </body>
  58. </html>