Page.IsValid
设置Display属性
Static
Dynamic
None
<span id="reqProductName" style="color:Red;Visibility:hidden;">(Required) </span>
<span id="reqProductName" style="color:Red;display:none;">(Required) </span>
Visibility和display都能隐藏文本但是visibility属性隐藏文本仍然会占用屏幕空间,display不占屏幕空间。
通常情况下,应当将验证控件的Display属性设置为Dynamic,不会将内容推到右边。
突出显示验证错误
<asp:RequiredFieldValidator ID="reqProductQuantity" ControlToValidate="txtProductQuantity"
Text="<img src='error.gif' alt='Fist name is required.'/>" Display="Dynamic" runat="server" />
SetFocusOnError="true"
<asp:RequiredFieldValidator ID="reqProductQuantity" ControlToValidate="txtProductQuantity"
Text="<img src='error.gif' alt='Fist name is required.'/>"
setFocusOnError="true"
Display="Dynamic" runat="server" />
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void btnLogin_Click(object sender, EventArgs e)
{
if (Page.IsValid)
lblLoginResult.Text = "Log in sucessful!";
}
protected void btnRegister_Click(object sender, EventArgs e)
{
if (Page.IsValid)
lblRegisterResult.Text = "Registration sucessful!";
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<style type="text/css">
html
{
background-color:Silver;
}
.column
{
float:left;
width:300px;
margin-left:10px;
background-color:White;
border:solid 1px black;
padding:10px;
}
</style>
<title>Show Validation Groups</title>
</head>
<body>
<form id="form1" runat="server">
<div class="column">
<fieldset>
<legend>Login</legend>
<p>
Please log in to our Website.
</p>
<asp:Label ID="lblUserName"
Text="User Name:"
AssociatedControlID="txtUserName" runat="server"></asp:Label>
<br />
<asp:TextBox ID="txtUserName" runat="server" />
<asp:RequiredFieldValidator ID="reqUserName"
ControlToValidate="txtUserName" Text="(Required)" ValidationGroup="LoginGroup" runat="server" />
<br /><br />
<asp:Label ID="lblPassword" Text="Password:" AssociatedControlID="txtPassword" runat="server" />
<br />
<asp:TextBox ID="txtPassword" TextMode="Password" runat="server" />
<asp:RequiredFieldValidator ID="reqPassword" ControlToValidate="txtPassword" Text="(Required)"
ValidationGroup="LoginGroup" Runat="server"/>
<br /><br />
<asp:Button ID="btnLogin" Text="Login" ValidationGroup="LoginGroup" runat="server" OnClick="btnLogin_Click" />
</fieldset>
<asp:Label ID="lblLoginResult" runat="server" />
</div>
<div class="column">
<fieldset>
<legend>Register</legend>
<p>If you do not have a User Name,please register at our WebSite.</p>
<asp:Label ID="lblFirstName" Text="First Name:"
AssociatedControlID="txtFirstName" runat="server" />
<br />
<asp:TextBox ID="txtFirstName" runat="server" />
<asp:RequiredFieldValidator ID="reqFirstName" ControlToValidate="txtFirstName"
Text="(Required)" ValidationGroup="RigsterGroup" runat="server" />
<br /><br />
<asp:Label ID="lblLastName" Text="Last Name:"
AssociatedControlID="txtLastName" runat="server" />
<br />
<asp:TextBox ID="txtLastName" runat="server" />
<asp:RequiredFieldValidator ID="reqLastName" ControlToValidate="txtLastName"
Text="(Required)" ValidationGroup="RigsterGroup" runat="server" />
<br /><br />
<asp:Button ID="btnRegister" Text="Register" ValidationGroup="RigsterGroup" runat="server" OnClick="btnRegister_Click" />
</fieldset>
<asp:Label ID="lblRegisterResult" runat="server" />
</div>
</form>
</body>
</html>
2011-4-26 11:32 danny
设置Display属性
Static
Dynamic
None
<span id="reqProductName" style="color:Red;Visibility:hidden;">(Required) </span>
<span id="reqProductName" style="color:Red;display:none;">(Required) </span>
Visibility和display都能隐藏文本但是visibility属性隐藏文本仍然会占用屏幕空间,display不占屏幕空间。
通常情况下,应当将验证控件的Display属性设置为Dynamic,不会将内容推到右边。
突出显示验证错误
<asp:RequiredFieldValidator ID="reqProductQuantity" ControlToValidate="txtProductQuantity"
Text="<img src='error.gif' alt='Fist name is required.'/>" Display="Dynamic" runat="server" />
SetFocusOnError="true"
<asp:RequiredFieldValidator ID="reqProductQuantity" ControlToValidate="txtProductQuantity"
Text="<img src='error.gif' alt='Fist name is required.'/>"
setFocusOnError="true"
Display="Dynamic" runat="server" />
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void btnLogin_Click(object sender, EventArgs e)
{
if (Page.IsValid)
lblLoginResult.Text = "Log in sucessful!";
}
protected void btnRegister_Click(object sender, EventArgs e)
{
if (Page.IsValid)
lblRegisterResult.Text = "Registration sucessful!";
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<style type="text/css">
html
{
background-color:Silver;
}
.column
{
float:left;
width:300px;
margin-left:10px;
background-color:White;
border:solid 1px black;
padding:10px;
}
</style>
<title>Show Validation Groups</title>
</head>
<body>
<form id="form1" runat="server">
<div class="column">
<fieldset>
<legend>Login</legend>
<p>
Please log in to our Website.
</p>
<asp:Label ID="lblUserName"
Text="User Name:"
AssociatedControlID="txtUserName" runat="server"></asp:Label>
<br />
<asp:TextBox ID="txtUserName" runat="server" />
<asp:RequiredFieldValidator ID="reqUserName"
ControlToValidate="txtUserName" Text="(Required)" ValidationGroup="LoginGroup" runat="server" />
<br /><br />
<asp:Label ID="lblPassword" Text="Password:" AssociatedControlID="txtPassword" runat="server" />
<br />
<asp:TextBox ID="txtPassword" TextMode="Password" runat="server" />
<asp:RequiredFieldValidator ID="reqPassword" ControlToValidate="txtPassword" Text="(Required)"
ValidationGroup="LoginGroup" Runat="server"/>
<br /><br />
<asp:Button ID="btnLogin" Text="Login" ValidationGroup="LoginGroup" runat="server" OnClick="btnLogin_Click" />
</fieldset>
<asp:Label ID="lblLoginResult" runat="server" />
</div>
<div class="column">
<fieldset>
<legend>Register</legend>
<p>If you do not have a User Name,please register at our WebSite.</p>
<asp:Label ID="lblFirstName" Text="First Name:"
AssociatedControlID="txtFirstName" runat="server" />
<br />
<asp:TextBox ID="txtFirstName" runat="server" />
<asp:RequiredFieldValidator ID="reqFirstName" ControlToValidate="txtFirstName"
Text="(Required)" ValidationGroup="RigsterGroup" runat="server" />
<br /><br />
<asp:Label ID="lblLastName" Text="Last Name:"
AssociatedControlID="txtLastName" runat="server" />
<br />
<asp:TextBox ID="txtLastName" runat="server" />
<asp:RequiredFieldValidator ID="reqLastName" ControlToValidate="txtLastName"
Text="(Required)" ValidationGroup="RigsterGroup" runat="server" />
<br /><br />
<asp:Button ID="btnRegister" Text="Register" ValidationGroup="RigsterGroup" runat="server" OnClick="btnRegister_Click" />
</fieldset>
<asp:Label ID="lblRegisterResult" runat="server" />
</div>
</form>
</body>
</html>
2011-4-26 11:32 danny
发表评论
-
19.5创建分层的SQL数据源控件
2011-06-01 09:18 875创建分层的SQL数据源控件 SqlHierarchicald ... -
19.4使用TreeView控件
2011-05-20 13:27 1245使用TreeView控件 1、声明式地添加树视图节点 Tr ... -
19.3使用Menu控件
2011-05-20 09:16 856使用Menu控件 1、声明式添加Menu条目 MenuHy ... -
7.3动态加载用户控件
2011-05-12 09:18 596动态加载用户控件 可以在运行时动态加载用户控件并将其显示在页 ... -
7.2Ajax和用户控件
2011-05-11 21:25 668Ajax和用户控件 RandomQuotation.ascx ... -
7.1创建用户控件
2011-05-11 13:15 610创建用户控件 简单例 ... -
6.4创建全局主题
2011-05-11 09:33 520创建全局主题 可以在一个Web服务器端上的多个程序之间共享同 ... -
6.3在主题中添加CSS
2011-05-10 21:22 515在主题中添加CSS 如果在主题文件夹中添加CSS文件,则在页 ... -
6.2在主题中添加皮肤
2011-05-10 09:09 901在主题中添加皮肤 一个主题可以包含一个或多个皮肤文件。可以通 ... -
6.1创建主题
2011-05-09 22:26 644创建主题 在名为App_Themes的应用程序的文件夹中新增文 ... -
5.3动态加载母版页
2011-05-09 12:50 756动态加载母版页 应用场合: 1)通过加载不同的母版页可以让网站 ... -
5.2修改母版页内容
2011-05-09 09:14 1253修改母版页内容 1、使用Title属性 <%@Pag ... -
5.1创建母版本页
2011-05-06 21:27 651创建母版本页 <%@ Master Language= ... -
4.1.3、上传大文件
2011-05-06 12:55 666上传大文件 上传大文件,需要做些处理 处理大文件时,需要使 ... -
4.1.2、文件保存到数据库
2011-05-06 09:13 5132、文件保存到数据库 上传 <%@ Page La ... -
4.1.1、文件保存到文件夹
2011-05-05 19:22 7412、文件保存到数据库 上传 <%@ Page Lan ... -
4.1接收上传文件
2011-05-05 09:14 607接收上传文件 FileUpload 控件属性 Enabled ... -
3.10创建自定义验证控件
2011-05-04 09:12 537创建自定义验证控件 BaseValidator类 抽象类 必 ... -
3.9使用ValidationSummary控件
2011-05-03 22:43 942使用ValidationSummary控件 在页面中的一处地 ... -
3.8使用CustomValidator控件
2011-05-03 11:21 642使用CustomValidator控件 CustomVali ...
相关推荐
Querying if the input is valid 14.5.3.2. Getting Invalid, Missing, or Unknown Fields 14.5.3.3. Getting Valid Fields 14.5.4. Using Metacommands to Control Filter or Validator Rules 14.5.4.1. The ...
2.2.4 Data Page Pointer (DP) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-10 2.2.5 Stack Pointer (SP) . . . . . . . . . . . . . . . . . . . . . . . . . ....
Recipe 3.2. Finding Last Friday Recipe 3.3. Calculating Time Periods in a Date Range Recipe 3.4. Summing Durations of Songs Recipe 3.5. Calculating the Number of Weekdays Between Two Dates ...
if form.is_valid(): form.save() return redirect('success_url') # Redirect to a success URL else: form = PublisherForm() return render(request, 'books/publisher_add.html', {'form': form}) ``` #...
3.2 Reduced mll Interface 3.3 10 Mb Serial Network Interface(SNI) .22 3. 4 802.3u Mll Serial Management Interface 3.4.1 Serial Management Register Access 3.4.2 Serial Management Access protocol 22 ...
3.1.2 使用Page.IsValid 85 3.1.3 设置Display属性 86 3.1.4 突出显示验证错误 86 3.1.5 使用验证组 90 3.1.6 禁用验证 93 3.2 使用RequiredFieldValidator控件 94 3.3 使用RangeValidator控件 97 3.4 使用...