Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 9 進階 Web 控制項. 資料驗證 Web 控制項 RequireFieldValidator RequireFieldValidator <asp:RequireFieldValidator id=“control name” runat=“server” ControlToValidate=“ID.

Similar presentations


Presentation on theme: "Chapter 9 進階 Web 控制項. 資料驗證 Web 控制項 RequireFieldValidator RequireFieldValidator <asp:RequireFieldValidator id=“control name” runat=“server” ControlToValidate=“ID."— Presentation transcript:

1 Chapter 9 進階 Web 控制項

2 資料驗證 Web 控制項 RequireFieldValidator RequireFieldValidator <asp:RequireFieldValidator id=“control name” runat=“server” ControlToValidate=“ID of the control that you want to validate” Display=“Static/Dynamic/None” ErrorMessage=“Error Message” InitialValue=“some text” Text=“error message displayed by the control” /> Displayed in the ValidationSummary control. This error message is displayed by the control when the text property is not set. Display in a textbox but will not be submitted

3 RequireFieldValidator RequireFieldValidator 資料驗證 Web 控制項 … <asp:RequiredFieldValidator id=“Validor1” ControlToValidate=“txtUsername” Text=“You must enter a username!” runat=“server” /> … … Sub B1_Click(s as object, e as Eventargs) If Page.IsValid Then … End If End Sub 所有控制項都通過驗證 Validor1.IsValid

4 資料驗證 Web 控制項 CompareValidator CompareValidator <asp:CompareValidator id=“control name” runat=“server” ControlToValidate=“ID of the control that you want to validate” Display=“Static/Dynamic/None” ErrorMessage=“Error Message” Operator=“DataTypeCheck/Equal/NotEqual/GreaterThan/ GreaterThanEqual/LessThan/LessThanEqual” Type=“Currency/Date/Double/Integer/String/…” ControlToCompare=“id of the control to use for comparing values” Text=“error message displayed by the control” />

5 資料驗證 Web 控制項 CompareValidator CompareValidator The CompareValidator is pretty particular about the dates that it will accept. January 1, 2001 Jan 1, 2001 For example not considered valid 1/1/2001 1-1-2001 Valid

6 資料驗證 Web 控制項 CompareValidator CompareValidator … <asp:CompareValidator ControltoValidator=“txtEndDate” ControlToCompare=“txtStartDate” Display=“Dynamic” Text=“End date must be greater than start date” Operator=“GreaterThan” Type=“Date” Runat=“Server” /> …

7 資料驗證 Web 控制項 RangeValidator RangeValidator <asp:RangeValidator id=“control name” runat=“server” ControlToValidate=“ID of the control that you want to validate” Display=“Static/Dynamic/None” ErrorMessage=“Error Message” MinimumValue=“minimum value” MaximumValue=“maximum value” Type=“Currency/Date/Double/Integer/String/…” Text=“error message displayed by the control” />

8 資料驗證 Web 控制項 RangeValidator RangeValidator Sub Page_Load V1.MinimumValue=Now.Date V1.MaximumValue=Now.Date.AddMonths(3) End Sub … … <asp:RangeValidator id=V1” runat=“server” ControlToValidate=“txtMeetingDate” Text=“Date must be in the next 3 months” Type=“Date” /> …

9 資料驗證 Web 控制項 RegularExpressionValidator RegularExpressionValidator <asp:RegularExpressionValidator id=“control name” runat=“server” ControlToValidate=“ID of the control that you want to validate” Display=“Static/Dynamic/None” ErrorMessage=“Error Message” ValidationExpression=“validation rule” Text=“error message displayed by the control” />

10 資料驗證 Web 控制項 RegularExpressionValidator RegularExpressionValidator ValidationExpression [] 單一字元內容 {} 輸入字元個數. 除了空白外所有的字元 * 最少 0 個 + 最少 1 個 ? 0 個或 1 個 ^ not | or \ 必需包含以上字元,含 ()

11 資料驗證 Web 控制項 RegularExpressionValidator RegularExpressionValidator ValidationExpression - Example [x-zX-Z] [win] [^linux] [a-zA-Z]{4} [a-zA-Z]{4,6} [a-zA-Z]{4,}.{4} [a-zA-Z]* [a-zA-Z]+ [a-zA-Z]{4} | [0-9]{4} \([0-9]{2,3}\) \w+ \d+ [01][0-9]:[0-5][0-9][ap]m [0-9]{2,4}-[0,9]{3,4}-[0-9]{3,4} \(?[0-9]{2,3}\)?-[0-9]{7}

12 資料驗證 Web 控制項 CustomValidator CustomValidator <asp:CustomValidator id=“control name” runat=“server” ControlToValidate=“ID of the control that you want to validate” Display=“Static/Dynamic/None” ErrorMessage=“Error Message” onServerValidate=“Server Validate Event” Text=“error message displayed by the control” />

13 資料驗證 Web 控制項 CustomValidator CustomValidator Example : See Text Book p. 377


Download ppt "Chapter 9 進階 Web 控制項. 資料驗證 Web 控制項 RequireFieldValidator RequireFieldValidator <asp:RequireFieldValidator id=“control name” runat=“server” ControlToValidate=“ID."

Similar presentations


Ads by Google