UpdatePanelWizardValidatorsCS.aspx 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
  5. {
  6. // Business logic to determine if performance is available.
  7. // For demonstration we are not allowing matinee tickets.
  8. args.IsValid = false;
  9. if (DropDownList1.SelectedIndex > 0)
  10. {
  11. args.IsValid = true;
  12. }
  13. }
  14. protected void Calendar1_SelectionChanged(object sender, EventArgs e)
  15. {
  16. TextBox3.Text = Calendar1.SelectedDate.ToShortDateString();
  17. }
  18. protected void Page_Load(object sender, EventArgs e)
  19. {
  20. CompareValidator1.ValueToCompare = DateTime.Today.ToShortDateString();
  21. }
  22. </script>
  23. <html xmlns="http://www.w3.org/1999/xhtml">
  24. <head id="Head1" runat="server">
  25. <title>UpdatePanel with Wizard and Validators Example</title>
  26. </head>
  27. <body>
  28. <form id="form1" runat="server">
  29. <div>
  30. <asp:ScriptManager ID="ScriptManager1" EnablePartialRendering="true" runat="server" >
  31. </asp:ScriptManager>
  32. <asp:UpdatePanel ID="WizardUpdatePanel" UpdateMode="conditional"
  33. runat="server">
  34. <ContentTemplate>
  35. <asp:Wizard ID="Wizard1" runat="server" ActiveStepIndex="0" BackColor="#EFF3FB"
  36. BorderColor="#B5C7DE" BorderWidth="1px" Font-Names="Verdana"
  37. Font-Size="0.8em" Width="460px">
  38. <StepStyle Font-Size="0.8em" ForeColor="#333333" />
  39. <SideBarStyle BackColor="#507CD1" Font-Size="0.9em" VerticalAlign="Top" />
  40. <NavigationButtonStyle BackColor="White" BorderColor="#507CD1"
  41. BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana"
  42. Font-Size="0.8em" ForeColor="#284E98" />
  43. <WizardSteps>
  44. <asp:WizardStep ID="WizardStep1" runat="server" StepType="Start" Title="Specify Tickets">
  45. <asp:Label ID="Label1" runat="server" Text="Enter a number 1 to 10:"></asp:Label>
  46. <asp:TextBox ID="TextBox1" runat="server" Width="50px"></asp:TextBox>
  47. <br />
  48. <asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="TextBox1"
  49. Display="Dynamic" ErrorMessage="Out of range!" MaximumValue="10"
  50. MinimumValue="1" Type="Integer"></asp:RangeValidator>
  51. <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
  52. ControlToValidate="TextBox1" Display="Dynamic" ErrorMessage="Required!"></asp:RequiredFieldValidator><br />
  53. <asp:Label ID="Label2" runat="server" Text="Enter an email address:"></asp:Label>
  54. <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
  55. <br />
  56. <asp:RegularExpressionValidator ID="RegularExpressionValidator1"
  57. runat="server" ControlToValidate="TextBox2" Display="Dynamic"
  58. 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})$"></asp:RegularExpressionValidator>
  59. <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
  60. ControlToValidate="TextBox2" Display="Dynamic" ErrorMessage="Required!"></asp:RequiredFieldValidator><br />
  61. </asp:WizardStep>
  62. <asp:WizardStep ID="WizardStep2" runat="server" Title="Select A Date" StepType="Finish">
  63. <div style="text-align: center">
  64. <asp:Calendar ID="Calendar1" runat="server" OnSelectionChanged="Calendar1_SelectionChanged">
  65. </asp:Calendar>
  66. </div>
  67. <br />
  68. <asp:Label ID="Label3" runat="server" Text="Choose a date to attend:"></asp:Label>
  69. <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
  70. <br />
  71. <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToValidate="TextBox3"
  72. ErrorMessage="Pick a date in the future!" Operator="GreaterThanEqual"
  73. Type="Date" Display="Dynamic"></asp:CompareValidator>
  74. <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
  75. ControlToValidate="TextBox3" Display="Dynamic" ErrorMessage="Required!"></asp:RequiredFieldValidator><br />
  76. Choose a performance:
  77. <asp:DropDownList ID="DropDownList1" runat="server">
  78. <asp:ListItem>matinee</asp:ListItem>
  79. <asp:ListItem>early evening</asp:ListItem>
  80. <asp:ListItem>late evening</asp:ListItem>
  81. </asp:DropDownList>
  82. <br />
  83. <asp:CustomValidator ID="CustomValidator1" runat="server" ControlToValidate="DropDownList1"
  84. ErrorMessage="That performance is not available." OnServerValidate="CustomValidator1_ServerValidate"></asp:CustomValidator><br />
  85. </asp:WizardStep>
  86. <asp:WizardStep ID="WizardStep3" runat="server" StepType="Complete" Title="See You There!">
  87. Your tickets will be sent in email. We look forward to seeing
  88. your there.
  89. </asp:WizardStep>
  90. </WizardSteps>
  91. <SideBarButtonStyle BackColor="#507CD1" Font-Names="Verdana"
  92. ForeColor="White" />
  93. <HeaderStyle BackColor="#284E98" BorderColor="#EFF3FB" BorderStyle="Solid"
  94. BorderWidth="2px" Font-Bold="True" Font-Size="0.9em" ForeColor="White"
  95. HorizontalAlign="Center" />
  96. <HeaderTemplate>
  97. Order Your Complimentary Tickets
  98. </HeaderTemplate>
  99. </asp:Wizard>
  100. </ContentTemplate>
  101. </asp:UpdatePanel>
  102. </div>
  103. </form>
  104. </body>
  105. </html>