⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 validate.aspx

📁 聊天 聊天 聊天 聊天 聊天 聊天
💻 ASPX
字号:
<%@ Page language="VB" %>
<html>
<head>
<script runat=server>
Sub ServerValidate (sender As Object, value As ServerValidateEventArgs)
	Dim num As Int32 = Int32.Parse(value.Value)
	response.write(num)
	if num= "10" then
		value.IsValid = True
	else
		value.IsValid = False
	end if
End Sub
public sub OnSubmit(source as Object, e as EventArgs)
	if Page.IsValid then
	    ' Check before update to database
	end if
end sub
</script>
<title>Validating with ASP+ Controls</title>
</head>
<body style="background-color='beige'; font-family='verdana'; font-size='10pt'">
<h2>ASP .NET Control Validation</h2>
<hr>

<form  RunAt="server">
<asp:ValidationSummary runat=server headertext="There were errors on the page:" />
<B>Required Field :</B><br><br>
Name : <input type=text runat=server id=txtName>
<asp:RequiredFieldValidator runat=server 
            controltovalidate=txtName
            errormessage="Name is required.">*
        </asp:RequiredFieldValidator>
<hr>
Password:<asp:TextBox id="txtPassword" RunAt="server"/>
	<br>
	Confirm:<asp:TextBox id="txtConfirm" RunAt="server"/>
	<asp:CompareValidator 
		id="cvPassword"
		ControlToValidate="txtPassword"
		ControlToCompare="txtConfirm"
		Type="String"
		Operator=Equal
		Display="dynamic"
		ErrorMessage="The password does not match the confirm password!"
		RunAt="server"
		>
		*
	</asp:CompareValidator>
<hr>
Range Validator <br><br>
IQ (180 - 265):<asp:TextBox id="iq" RunAt="server"/>
	<asp:RangeValidator 
		id="rvIQ"
		ControlToValidate="iq"
		Display="dynamic"
		ErrorMessage="IQ must be between 180 and 265 to run this example"
		MinimumValue=180
		MaximumValue=265
		Type="Integer"
		RunAt="server"
		>
	</asp:RangeValidator>
<br>
Regular Expression: <br> <br>
validation expression : [0-9]{3}\s[0-9]{3}-[0-9]{4}<br>
Example : 214 345-0458
<br><br>
Phone:<asp:TextBox id="txtPhone" RunAt="server" />
	<asp:RegularExpressionValidator
		id="revPassword"
		ControlToValidate="txtPhone"
		Display="dynamic"
		ValidationExpression="[0-9]{3}\s[0-9]{3}-[0-9]{4}"
		ErrorMessage="Phone number must be xxx xxx-xxxx"
		RunAt="server"
		>
	</asp:RegularExpressionValidator>
<hr>
Custom Validation: <br><br>
Must be the number 10
<asp:TextBox id=Text11 runat="server" />
    &nbsp&nbsp
    <asp:CustomValidator id="CustomValidator1" runat="server"
        ControlToValidate="Text11"
        OnServerValidate="ServerValidate"
        Display="Static"
        Font-Name="verdana" Font-Size="10pt">
           This field must be the number 10!
    </asp:CustomValidator>
    <br>
<hr>
<input type=submit runat=server id=cmdSubmit value=Submit onserverclick=OnSubmit>
</form>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -