UpdatePanel1CS.aspx 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <%@ Page Language="C#" %>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  3. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4. <script runat="server">
  5. protected void ChosenDate_TextChanged(object sender, EventArgs e)
  6. {
  7. DateTime dt = new DateTime();
  8. DateTime.TryParse(ChosenDate.Text, out dt);
  9. CalendarPicker.SelectedDate = dt;
  10. CalendarPicker.VisibleDate = dt;
  11. }
  12. protected void Close_Click(object sender, EventArgs e)
  13. {
  14. SetDateSelectionAndVisible();
  15. }
  16. protected void ShowDatePickerPopOut_Click(object sender, ImageClickEventArgs e)
  17. {
  18. DatePickerPopOut.Visible = !DatePickerPopOut.Visible;
  19. }
  20. protected void CalendarPicker_SelectionChanged(object sender, EventArgs e)
  21. {
  22. SetDateSelectionAndVisible();
  23. }
  24. private void SetDateSelectionAndVisible()
  25. {
  26. if (CalendarPicker.SelectedDates.Count != 0)
  27. ChosenDate.Text = CalendarPicker.SelectedDate.ToShortDateString();
  28. DatePickerPopOut.Visible = false;
  29. }
  30. protected void SubmitButton_Click(object sender, EventArgs e)
  31. {
  32. if (Page.IsValid)
  33. {
  34. MessageLabel.Text = "An email with availability was sent.";
  35. }
  36. else
  37. {
  38. MessageLabel.Text = "";
  39. }
  40. }
  41. protected void Page_Load(object sender, EventArgs e)
  42. {
  43. CompareValidatorDate.ValueToCompare = DateTime.Today.ToShortDateString();
  44. }
  45. </script>
  46. <html xmlns="http://www.w3.org/1999/xhtml">
  47. <head id="Head1" runat="server">
  48. <title>Calendar Popup Example</title>
  49. <style type="text/css">
  50. body {
  51. font-family: Tahoma;
  52. }
  53. .PopUpCalendarStyle
  54. {
  55. background-color:lightblue;
  56. position:absolute;
  57. visibility:show;
  58. margin: 15px 0px 0px 10px;
  59. z-index:99;
  60. border: solid 2px black;
  61. }
  62. .UpdatePanelContainer
  63. {
  64. width: 260px;
  65. height:110px;
  66. }
  67. </style>
  68. </head>
  69. <body>
  70. <form id="form1" runat="server">
  71. <asp:ScriptManager ID="ScriptManager1" runat="server" />
  72. <asp:UpdatePanel runat="server" ID="UpdatePanel1" UpdateMode="Conditional">
  73. <ContentTemplate>
  74. <fieldset id="FieldSet1" class="FieldSetStyle" runat="server">
  75. <legend>Check Ticket Availability</legend>Date
  76. <asp:TextBox runat="server" ID="ChosenDate" OnTextChanged="ChosenDate_TextChanged" />
  77. <asp:ImageButton runat="server" ID="ShowDatePickerPopOut" OnClick="ShowDatePickerPopOut_Click"
  78. ImageUrl="images/calendar.gif" AlternateText="Choose a date."
  79. Height="20px" Width="20px" />
  80. <asp:Panel ID="DatePickerPopOut" CssClass="PopUpCalendarStyle"
  81. Visible="false" runat="server">
  82. <asp:Calendar ID="CalendarPicker" runat="server" OnSelectionChanged="CalendarPicker_SelectionChanged">
  83. </asp:Calendar>
  84. <br />
  85. <asp:LinkButton ID="CloseDatePickerPopOut" runat="server" Font-Size="small"
  86. OnClick="Close_Click" ToolTip="Close Pop out">
  87. Close
  88. </asp:LinkButton>
  89. </asp:Panel>
  90. <br />
  91. Email
  92. <asp:TextBox runat="server" ID="EmailTextBox" />
  93. <br /><br />
  94. <asp:Button ID="SubmitButton" Text="Check" runat="server" ValidationGroup="RequiredFields" OnClick="SubmitButton_Click" />
  95. <br />
  96. <asp:CompareValidator ID="CompareValidatorDate" runat="server"
  97. ControlToValidate="ChosenDate" ErrorMessage="Choose a date in the future."
  98. Operator="GreaterThanEqual" Type="Date" Display="None" ValidationGroup="RequiredFields" EnableClientScript="False"></asp:CompareValidator>
  99. <asp:RequiredFieldValidator ID="RequiredFieldValidatorDate" runat="server"
  100. ControlToValidate="ChosenDate" Display="None" ErrorMessage="Date is required."
  101. ValidationGroup="RequiredFields" EnableClientScript="False"></asp:RequiredFieldValidator>
  102. <asp:RegularExpressionValidator ID="RegularExpressionValidatorEmail"
  103. runat="server" ControlToValidate="EmailTextBox" Display="None" ValidationGroup="RequiredFields"
  104. ErrorMessage="The email was not correctly formatted." ValidationExpression="^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$" EnableClientScript="False"></asp:RegularExpressionValidator>
  105. <asp:RequiredFieldValidator ID="RequiredFieldValidatorEmail" runat="server" ValidationGroup="RequiredFields"
  106. ControlToValidate="EmailTextBox" Display="None" ErrorMessage="Email is required." EnableClientScript="False"></asp:RequiredFieldValidator><br />
  107. <asp:ValidationSummary ID="ValidationSummary1" runat="server"
  108. ValidationGroup="RequiredFields" EnableClientScript="False" />
  109. <asp:Label ID="MessageLabel" runat="server" />
  110. </fieldset>
  111. </ContentTemplate>
  112. </asp:UpdatePanel>
  113. </form>
  114. </body>
  115. </html>