Share via


HtmlButton.CausesValidation 속성

정의

HtmlButton 컨트롤을 클릭할 때 유효성 검사가 수행되는지 여부를 나타내는 값을 가져오거나 설정합니다.

public:
 property bool CausesValidation { bool get(); void set(bool value); };
public:
 virtual property bool CausesValidation { bool get(); void set(bool value); };
public bool CausesValidation { get; set; }
public virtual bool CausesValidation { get; set; }
member this.CausesValidation : bool with get, set
Public Property CausesValidation As Boolean
Public Overridable Property CausesValidation As Boolean

속성 값

true 컨트롤을 클릭할 때 유효성 검사가 수행되면 HtmlButton이고, 그렇지 않으면 false입니다. 기본값은 true입니다.

예제

다음 코드 예제를 사용 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 xmlns="http://www.w3.org/1999/xhtml" > 

<head>
    <title> HtmlButton CausesValidation Example </title>
<script runat="server">

      void SubmitButton_Click(Object sender, EventArgs e)
      {
         
         // Determine which button was clicked.
         switch(((HtmlButton)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.InnerHtml = "You have chosen to run a query for the following city: " + 
                     CityTextBox.Value;
               }

               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.InnerHtml = "You have chosen to run a query for the following state: " + 
                     StateTextBox.Value;
               }

               break;

            default:

               // If the button clicked is not recognized, erase the message on the page.
               Message.InnerHtml = "";

               break;

         }
        
      }

   </script>

</head>

<body>

   <form id="form1" runat="server">

      <h3> HtmlButton CausesValidation Example </h3>

      <table border="1" cellpadding="10">
         <tr>
            <td>
               <b>Enter city to query.</b> <br />
               <input id="CityTextBox" 
                      type="Text"
                      runat="server"/>
               <asp:RequiredFieldValidator ID="CityReqValidator"
                    ControlToValidate="CityTextBox"
                    ErrorMessage="<br />Please enter a city."
                    Display="Dynamic"
                    EnableClientScript="False"
                    runat="server"/>
            </td>
            <td valign="bottom">
               <button id="CityQueryButton"
                       causesvalidation="False"
                       onserverclick="SubmitButton_Click"
                       runat="server">
                  Submit
               </button>
            </td>
         </tr>

         <tr>
            <td>
               <b>Enter state to query.</b> <br />
               <input id="StateTextBox" 
                      type="Text" 
                      runat="server"/>
               <asp:RequiredFieldValidator ID="StateReqValidator"
                    ControlToValidate="StateTextBox"
                    ErrorMessage="<br />Please enter a state."
                    Display="Dynamic"
                    EnableClientScript="False"
                    runat="server"/>
            </td>
            <td valign="bottom">
               <button id="StateQueryButton"
                       causesvalidation="False"
                       onserverclick="SubmitButton_Click"
                       runat="server">
                  Submit
               </button>
            </td>
         </tr>

      </table>

      <br /><br />

      <span id="Message"
            runat="Server"/>


   </form>

</body>
</html>

<%@ Page Language="VB" AutoEventWireup="True" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" > 

<head>
    <title> HtmlButton CausesValidation Example </title>
<script runat="server">

      Sub SubmitButton_Click(sender As Object, e As EventArgs)
         
         ' Determine which button was clicked.
         Select Case (CType(sender, HtmlButton)).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.InnerHtml = "You have chosen to run a query for the following city: " & _ 
                     CityTextBox.Value
               
               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.InnerHtml = "You have chosen to run a query for the following state: " & _ 
                     StateTextBox.Value
               
               End If

            Case Else

               ' If the button clicked is not recognized, erase the message on the page.
               Message.InnerHtml = ""

         End Select
        
      End Sub

   </script>

</head>

<body>

   <form id="form1" runat="server">

      <h3> HtmlButton CausesValidation Example </h3>

      <table border="1" cellpadding="10">
         <tr>
            <td>
               <b>Enter city to query.</b> <br />
               <input id="CityTextBox" 
                      type="Text"
                      runat="server"/>
               <asp:RequiredFieldValidator ID="CityReqValidator"
                    ControlToValidate="CityTextBox"
                    ErrorMessage="<br />Please enter a city."
                    Display="Dynamic"
                    EnableClientScript="False"
                    runat="server"/>
            </td>
            <td valign="bottom">
               <button id="CityQueryButton"
                       causesvalidation="False"
                       onserverclick="SubmitButton_Click"
                       runat="server">
                  Submit
               </button>
            </td>
         </tr>

         <tr>
            <td>
               <b>Enter state to query.</b> <br />
               <input id="StateTextBox" 
                      type="Text" 
                      runat="server"/>
               <asp:RequiredFieldValidator ID="StateReqValidator"
                    ControlToValidate="StateTextBox"
                    ErrorMessage="<br />Please enter a state."
                    Display="Dynamic"
                    EnableClientScript="False"
                    runat="server"/>
            </td>
            <td valign="bottom">
               <button id="StateQueryButton"
                       causesvalidation="False"
                       onserverclick="SubmitButton_Click"
                       runat="server">
                  Submit
               </button>
            </td>
         </tr>

      </table>

      <br /><br />

      <span id="Message"
            runat="Server"/>


   </form>

</body>
</html>

설명

기본적으로 페이지 유효성 검사는 컨트롤을 클릭할 HtmlButton 때 수행 됩니다. 페이지 유효성 검사는 페이지의 유효성 검사 컨트롤과 연결된 입력 컨트롤이 모두 유효성 검사 컨트롤에 지정된 유효성 검사 규칙을 통과하는지 여부를 결정합니다.

속성을 사용하여 CausesValidation 컨트롤을 클릭할 때 HtmlButton 클라이언트와 서버 모두에서 유효성 검사가 수행되는지 여부를 지정하거나 확인할 수 있습니다. 유효성 검사가 수행 되지를 방지 하려면 설정 합니다 CausesValidation 속성을 false입니다.

이 속성은 취소 또는 다시 설정 단추를 클릭할 때 페이지 유효성 검사가 발생 하지 않도록 이벤트에 대 ServerClick 한 이벤트 처리기에서 일반적으로 사용 됩니다.

적용 대상

추가 정보