`
justdoithz
  • 浏览: 48691 次
  • 性别: Icon_minigender_1
  • 来自: 成都
文章分类
社区版块
存档分类
最新评论

Button..::.CausesValidation 属性

阅读更多

获取或设置一个值,该值指示在单击 Button 控件时是否执行验证。

ASP.NET
<asp:Button CausesValidation="True|False" />

属性值

类型:System..::.Boolean

如果在单击 Button 控件时执行验证,则为 true;否则为 false。默认值为 true

实现

IButtonControl..::.CausesValidation

<!---->

默认情况下,单击 Button 控件时执行页验证。页验证确定页上与验证控件关联的输入控件是否均通过该验证控件所指定的验证规则。

通过使用 CausesValidation 属性,可以指定或确定当单击 Button 控件时,是否同时在客户端和服务器上执行验证。若要禁止执行验证,请将 CausesValidation 属性设置为 false

说明:

当使用 PostBackUrl 属性回发至不同页面时,应将 CausesValidation 属性设置为 false。在回发至不同页面时,应对验证进行显式检查。有关示例,请参见 PostBackUrl 属性的“备注”部分。

对于 resetclear 按钮,此属性通常设置为 false,以防止在单击其中某个按钮时执行验证。

CausesValidation 属性的值设置为 true 时,还可以使用 ValidationGroup 属性来指定 Button 控件引发验证时所对应的验证组的名称。

无法通过主题或样式表主题设置此属性。有关更多信息,请参见 ThemeableAttributeASP.NET 主题和外观概述

<!---->

下面的代码示例演示如何使用 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>

分享到:
评论

相关推荐

    Visual C# 2008控件\C#.net 2008例子(11.12)\第3章

    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 CausesValidation 说明

    此文档简述了ASP.NET当中关于form上各个组件的CauseValidation的详细用法

    VB 计算器 VB计算器 VB.NET计算器 C#计算器

    &lt;asp:TextBox ID="TextBox1" runat="server" BorderStyle="Solid" BorderWidth="1px" Width="180px" CausesValidation="True" OnTextChanged="TextBox1_TextChanged" ForeColor="Transparent"&gt;0&lt;/asp:TextBox&gt; ...

    visual c#.net 2008控件使用范例大全

    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...

    2.ASP.NET.2.0.高级编程(第4版) [1/7]

    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 ...

    Visual C# 2008控件\C#.net 2008例子(11.12)\第2章

    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控件\C#.net 2008例子(11.12\第1章

    《Visual C# 2008控件使用范例详解》作者拥有10年的编程经验,通过近200个范例的典型应用,帮助读者透彻理解Visual C#2008的控件及其应用。全书共分13章,分别介绍了...1.3.3 CausesValidation属性 1.3.4 其他常用属性

    ASP.NET2.0高级编程(第4版)1/6

    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服务器...

    十天学会ASP.net--我认为ASP.NET比ASP难很多,希望大家做好准备

    以前说到BUTTON控件CausesValidation=true/false来设置按钮提交的表单是不是被检验也就是这里的几个检验控件,如果CausesValidation=true的话按下按钮就会首先检测是不是都通过了检验控件的检验。 下面再说两点: ...

    Visual Basic 6编程技术大全 中译本扫描版带书签 2/2

    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...

    Visual Basic 6编程技术大全 中译本扫描版带书签 1/2

    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中 CheckBox复选框控件的使用

    我们可以使用两种类型的 ASP.NET 控件将复选框添加到 Web 窗体页上:单独的 CheckBox ...CausesValidation 规定点击 Button 控件时是否执行验证。 2.0 Checked 规定是否已选中该复选框。 1.0 InputAttributes 该

    asp设计的会员管理系统

    &lt;asp:Button ID="FindPass" runat="server" Text="忘记密码" BorderStyle="Ridge" Font-size="9pt" BorderWidth=1 OnClick="FindPass_Click" CausesValidation=false /&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...

    ASP.NET中 TextBox 文本输入框控件的使用方法

    CausesValidation 获取或设置一个值,该值指示当TextBox控件设置为在回发发生时进行验证,是否执行验证 ID 控件ID Text 控件要显示的文本 TextMode 获取或设置TextBox控件的行为模式(单行、多行或密码) W

    客户关系管理系统(.NET)

    &lt;asp:Button ID="btnDelete" runat="server" CausesValidation="False" CommandName="Delete" Text="删除" OnClientClick="return confirm('是否选择删除?')" CssClass="button"/&gt; &lt;/ItemTemplate&gt;

    asp.net GridView模板列中实现选择行功能

    大部分的功能采用通过模板列实现,为了方便选择和删除使用了它自带的功能和方法,很容易就能实现,没发现有什么大问题...asp:LinkButton ID=”btnSelect” runat=”server” CausesValidation=”False” CommandName=”

    RadComboBox

    &lt;radc:radcombobox id="RadComboBox1" runat="server" allowcustomtext="True" causesvalidation="False" height="200px" markfirstmatch="True" maxlength="20" width="100px" DropDownWidth="150px"&gt;&lt;/radc:...

Global site tag (gtag.js) - Google Analytics