在A.aspx页面中同时引用了login.ascx和search.ascx两个用户控件,A.aspx页面中的button触发其它几个textbox控件的验证,但点击login.ascx和search.ascx中的button时也时会发textbox控件的验证,怎样才能使只有A.aspx页面中的button才可以触发textbox控件的验证的?
解决方案 »
- 高分求解,验证用户输入问题...
- 动态创建的Repeater为什么绑定数据只显示一条?
- 如何把一个用DREAMWEVER做的静态网页做成动态网页。用ASP。NET?
- asp.net 考试显示方式
- 如何用一个通用的方法给某自定义控件的某属性赋值?
- 为什么我的程序在本地运行正常,一传到空间里就出现这个错误?
- 大家帮我看看这个是什么:ASPNET.StarterKit.TimeTracker.BusinessLogicLayer
- 请问我在调试ASP。NET+ACCESS时需要安装OFFICE中的ACCESS组件吗
- 求:数组的整存,零取的问题?
- 这个container是什么东东
- 想找个兄弟应付下毕业设计
- 在用户控间中能访问宿主页面中的对象吗?比如说访问一个宿主页面的textbox
获取或设置一个值,该值指示在单击 Button 控件时是否执行了验证。[Visual Basic]
Public Property CausesValidation As Boolean[C#]
public bool CausesValidation {get; set;}[C++]
public: __property bool get_CausesValidation();
public: __property void set_CausesValidation(bool);[JScript]
public function get CausesValidation() : Boolean;
public function set CausesValidation(Boolean);属性值
如果在单击 Button 控件时执行了验证,则为 true;否则为 false。默认值为 true。备注
默认情况下,单击 Button 控件时会执行页验证。页验证确定页上与验证控件关联的输入控件是否均通过该验证控件所指定的验证规则。使用 CausesValidation 属性可以指定或确定当单击 Button 控件时是否对客户端和服务器都执行验证。若要禁止执行验证,请将 CausesValidation 属性设置为 false。对于 reset 或 clear 按钮,此属性通常设置为 false,以防止在单击其中某个按钮时执行验证。示例
[Visual Basic, C#] 下面的示例演示如何使用 CausesValidation 属性防止发生页面验证。请注意 Validate 方法如何独立地激活每个验证控件。[Visual Basic] <%@ Page Language="VB" AutoEventWireup="True" %><html> <head> <script runat="server"> Sub SubmitButton_Click(sender As Object, e As EventArgs)
' Determine which button was clicked.
Select Case (CType(sender, Button)).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 Then
Message.Text = "You have chosen to run a query for the following city: " & _
CityTextBox.Text
End If 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 Then
Message.Text = "You have chosen to run a query for the following state: " & _
StateTextBox.Text
End If Case Else ' If the button clicked isn't recognized, erase the message on the page.
Message.Text = "" End Select
End Sub </script></head><body> <form 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">
<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>[C#] <%@ Page Language="C#" AutoEventWireup="True" %><html> <head> <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 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">
<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>[C++, JScript] 没有可用于 C++ 或 JScript 的示例。若要查看 Visual Basic 或 C# 示例,请单击页左上角的“语言筛选器”按钮 。要求
但是这样一来login.ascx和search.ascx用户控件中的button也就不能触发自身textbox控件的验证啦