<!---->
下面的代码示例演示如何使用 CausesValidation 属性防止发生页验证。注意,Validate 方法会单独激活各个验证控件。
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head id="Head1" runat="server">
<title> Button CausesValidation Example </title>
<script runat="server">
void SubmitButton_Click(Object sender, EventArgs e)
{
// Determine which button was clicked.
switch(((Button)sender).ID)
{
case "CityQueryButton":
// Validate only the controls used for the city query.
CityReqValidator.Validate();
// Take the appropriate action if the controls pass validation.
if (CityReqValidator.IsValid)
{
Message.Text = "You have chosen to run a query for the following city: " +
CityTextBox.Text;
}
break;
case "StateQueryButton":
// Validate only the controls used for the state query.
StateReqValidator.Validate();
// Take the appropriate action if the controls pass validation.
if (StateReqValidator.IsValid)
{
Message.Text = "You have chosen to run a query for the following state: " +
StateTextBox.Text;
}
break;
default:
// If the button clicked isn't recognized, erase the message on the page.
Message.Text = "";
break;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h3> Button CausesValidation Example </h3>
<table border="1" cellpadding="10">
<tr>
<td>
<b>Enter city to query.</b> <br />
<asp:TextBox ID="CityTextBox"
runat="server"/>
<asp:RequiredFieldValidator ID="CityReqValidator"
ControlToValidate="CityTextBox"
ErrorMessage="<br />Please enter a city."
Display="Dynamic"
EnableClientScript="False"
runat="server"/>
</td>
<td valign="bottom">
<asp:Button ID="CityQueryButton"
Text="Submit"
CausesValidation="False"
OnClick="SubmitButton_Click"
runat="server"/>
</td>
</tr>
<tr>
<td>
<b>Enter state to query.</b> <br />
<asp:TextBox ID="StateTextBox"
runat="server"/>
<asp:RequiredFieldValidator ID="StateReqValidator"
ControlToValidate="StateTextBox"
ErrorMessage="<br />Please enter a state."
Display="Dynamic"
EnableClientScript="False"
runat="server"/>
</td>
<td valign="bottom">
<!-- 这里把 CausesValidation="false" 默认时为true 会对整个页面验证 (就是验证标签所做的验证) 这里如果没有OnClick="SubmitButton_Click" 则不会执行验证-->
<asp:Button ID="StateQueryButton"
Text="Submit"
CausesValidation="false"
OnClick="SubmitButton_Click"
runat="server"/>
</td>
</tr>
</table>
<br /><br />
<asp:Label ID="Message"
runat="Server"/>
</form>
</body>
</html>
相关推荐
3.4.3 CausesValidation属性 3.4.4.HidePromptOnleave属性 3.4.5 Mask属性 3.4.6 MaskCompleted属性 3.4.7 MaskFull属性 3.4.8 PasswordChar属性 3.4.9 TextMaskFormat属性 3.4.10 Skipterals属性 3.4.11 ...
此文档简述了ASP.NET当中关于form上各个组件的CauseValidation的详细用法
<asp:TextBox ID="TextBox1" runat="server" BorderStyle="Solid" BorderWidth="1px" Width="180px" CausesValidation="True" OnTextChanged="TextBox1_TextChanged" ForeColor="Transparent">0</asp:TextBox> ...
1.3.3 CausesValidation属性 1.3.4 其他常用属性 第2章 选择类控件 2.1 RadioButton控件 2.1.1 AllowDrop属性 2.1.2 Anchor属性 2.1.3 AutoEllipsis属性 2.1.4 设置控件背景的属性 2.1.5 FlatStyle和FlatAppearance...
5.5.1 CausesValidation属性 123 5.5.2 CommandName属性 123 5.5.3 使用客户端JavaScript的按钮 124 5.6 LinkButton服务器控件 126 5.7 ImageButton服务器控件 126 5.8 HyperLink服务器控件 128 5.9 ...
2.3.1 CausesValidation属性 2.3.2 CheckOnClick属性 2.3.3 ColumnWidth属性 2.3.4 Cursor属性 2.3.5 Dock属性 2.3.6 FormatStrin9和FormattingEnabled属性 2.3.7 HorizontalScroUBar和HorizontalExtent属性 2.3.8 ...
《Visual C# 2008控件使用范例详解》作者拥有10年的编程经验,通过近200个范例的典型应用,帮助读者透彻理解Visual C#2008的控件及其应用。全书共分13章,分别介绍了...1.3.3 CausesValidation属性 1.3.4 其他常用属性
5.5.1 CausesValidation属性123 5.5.2 CommandName属性123 5.5.3 使用客户端JavaScript 的按钮124 5.6 LinkButton服务器控件126 5.7 ImageButton服务器控件126 5.8 HyperLink服务器控件128 5.9 DropDownList服务器...
以前说到BUTTON控件CausesValidation=true/false来设置按钮提交的表单是不是被检验也就是这里的几个检验控件,如果CausesValidation=true的话按下按钮就会首先检测是不是都通过了检验控件的检验。 下面再说两点: ...
3.1.4 CausesValidation属性和Validate事件63 3.1.5自动跳格字段65 3.1.6格式化文本65 3.1.7多行TextBox控件69 3.2 Label和Frame控件70 3.2.1 Label控件70 3.2.2 Frame控件71 3.3 CommandButton、CheckBox和 Option...
3.1.4 CausesValidation属性和Validate事件63 3.1.5自动跳格字段65 3.1.6格式化文本65 3.1.7多行TextBox控件69 3.2 Label和Frame控件70 3.2.1 Label控件70 3.2.2 Frame控件71 3.3 CommandButton、CheckBox和 Option...
我们可以使用两种类型的 ASP.NET 控件将复选框添加到 Web 窗体页上:单独的 CheckBox ...CausesValidation 规定点击 Button 控件时是否执行验证。 2.0 Checked 规定是否已选中该复选框。 1.0 InputAttributes 该
<asp:Button ID="FindPass" runat="server" Text="忘记密码" BorderStyle="Ridge" Font-size="9pt" BorderWidth=1 OnClick="FindPass_Click" CausesValidation=false /> ...
CausesValidation 获取或设置一个值,该值指示当TextBox控件设置为在回发发生时进行验证,是否执行验证 ID 控件ID Text 控件要显示的文本 TextMode 获取或设置TextBox控件的行为模式(单行、多行或密码) W
<asp:Button ID="btnDelete" runat="server" CausesValidation="False" CommandName="Delete" Text="删除" OnClientClick="return confirm('是否选择删除?')" CssClass="button"/> </ItemTemplate>
大部分的功能采用通过模板列实现,为了方便选择和删除使用了它自带的功能和方法,很容易就能实现,没发现有什么大问题...asp:LinkButton ID=”btnSelect” runat=”server” CausesValidation=”False” CommandName=”
<radc:radcombobox id="RadComboBox1" runat="server" allowcustomtext="True" causesvalidation="False" height="200px" markfirstmatch="True" maxlength="20" width="100px" DropDownWidth="150px"></radc:...