ASP.Net/Validation by Function/Number — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 18:30, 26 мая 2010
Содержание
- 1 Checking the Range of a Number through the RangeValidator Control (VB.net)
- 2 Comparing a Field to a Numeric Data Type using the CompareValidator Control (VB.net)
- 3 Validating Against a Positive Even Whole Number using the CustomValidator Control (VB.net)
- 4 Validation control:a postive whole number (VB.net)
Checking the Range of a Number through the RangeValidator Control (VB.net)
<source lang="csharp">
<%@ Page Language=VB Debug=true %>
<HTML>
<HEAD>
<TITLE>Checking the Range of a Number through the RangeValidator Control</TITLE>
</HEAD>
<form runat="server">
Enter a Number:
<asp:textbox
id="txtNumber" runat=server
/> <asp:rangevalidator
id="rngQuantity" controltovalidate="txtNumber" type="Integer" minimumvalue=5 maximumvalue=44 display="Dynamic" font-name="Verdana" font-bold="True" font-size="10pt" forecolor="blue" runat="server"> The Quantity field must be from 5 to 44!
</asp:rangevalidator>
<asp:button
id="butOK" text="OK" type="Submit" runat="server"
/> </form> </BODY> </HTML>
</source>
Comparing a Field to a Numeric Data Type using the CompareValidator Control (VB.net)
<source lang="csharp">
<%@ Page Language=VB Debug=true %>
<HTML>
<HEAD>
<TITLE>Comparing a Field to a Numeric Data Type using the CompareValidator Control</TITLE>
</HEAD>
<form runat="server">
Please enter a Whole Number:
<asp:textbox
id="txtNumber" runat=server
/> <asp:comparevalidator
id="cvCheckNumber" controltovalidate="txtNumber" operator="DataTypeCheck" type="Integer" runat="server"
>
You must enter a whole number!
</asp:CompareValidator>
<asp:button
id="butOK" text="OK" type="Submit" runat="server"
/> </form> </BODY> </HTML>
</source>
Validating Against a Positive Even Whole Number using the CustomValidator Control (VB.net)
<source lang="csharp">
<%@ Page Language=VB Debug=true %> <script runat=server> Sub Answer_ServerValidation(source As object, E As ServerValidateEventArgs)
If E.Value = CLng(E.Value) Then If E.Value Mod 2 = 0 Then If E.Value > 0 Then E.IsValid = True Else E.IsValid = False End If Else E.IsValid = False End If Else E.IsValid = False End If
End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>Validating Against a Positive Even Whole Number using the CustomValidator Control</TITLE>
</HEAD>
<form runat="server">
Enter a Positive, Even, Whole Number:
<asp:textbox id="txtAnswer" runat=server />
<asp:customvalidator
id="custom9" controltovalidate="txtAnswer" OnServerValidate="Answer_ServerValidation" display="Dynamic" font-name="Verdana" font-bold="True" font-size="10pt" runat="server">
Incorrect answer please try again!
</asp:CustomValidator>
<asp:button
id="butOK" text="OK" type="Submit" runat="server"
/> </form> </BODY> </HTML>
</source>
Validation control:a postive whole number (VB.net)
<source lang="csharp">
<%@ Page
Inherits="System.Web.UI.MobileControls.MobilePage" Language="VB"
%> <%@ Register
TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile"
%> <script runat="server" language="VB"> Sub OK_OnSubmit(Sender As Object, E As EventArgs)
If cvCheckNumber.IsValid Then ActiveForm = FinishForm lbl2.Text = "You entered " & txtNumber.Text End If
End Sub </script> <mobile:form
id="StartForm" runat="server"> <mobile:label runat="server" id="lbl1" Text="Enter a postive whole number:" /> <mobile:textbox runat="server" id="txtNumber" /> <mobile:comparevalidator id="cvCheckNumber" controltovalidate="txtNumber" valuetocompare=0 operator="GreaterThan" errormessage="You must enter a positive whole number!" type="Integer" runat="server" /> <mobile:Command runat="server" id="cmdOK" OnClick="OK_OnSubmit" Text="OK" />
</mobile:form> <mobile:form
id="FinishForm" runat="server"> <mobile:label runat="server" id="lbl2" />
</mobile:form>
</source>