CustomValidator.ClientValidationFunction 속성

정의

유효성 검사에 사용되는 사용자 지정 클라이언트쪽 스크립트 함수의 이름을 가져오거나 설정합니다.

public:
 property System::String ^ ClientValidationFunction { System::String ^ get(); void set(System::String ^ value); };
public string ClientValidationFunction { get; set; }
[System.Web.UI.Themeable(false)]
public string ClientValidationFunction { get; set; }
member this.ClientValidationFunction : string with get, set
[<System.Web.UI.Themeable(false)>]
member this.ClientValidationFunction : string with get, set
Public Property ClientValidationFunction As String

속성 값

유효성 검사에 사용되는 사용자 지정 클라이언트 스크립트 함수의 이름입니다. 기본값은 Empty로, 이 속성이 설정되지 않았음을 나타냅니다. 함수 이름에는 괄호 또는 매개 변수를 사용할 수 없습니다.

특성

예제

다음 코드 예제를 사용 하는 방법에 설명 합니다 ClientValidationFunction 클라이언트 쪽 유효성 검사를 수행 하는 함수의 이름을 지정 하는 속성입니다. 유효성 검사는 짝수를 확인합니다. 함수 매개 변수의 내용은의 설명 섹션을 참조 하세요. CustomValidator합니다.

중요

이 예제에는 사용자 입력을 허용하는 텍스트 상자가 있으므로 보안상 위험할 수 있습니다. 기본적으로 ASP.NET 웹 페이지는 사용자 입력 내용에 스크립트 또는 HTML 요소가 포함되어 있지 않은지 확인합니다. 자세한 내용은 Script Exploits Overview를 참조하세요.

<%@ Page Language="C#" AutoEventWireup="True" %>

<html>
<head>

   <script runat="server">

      void ValidateBtn_OnClick(object sender, EventArgs e) 
      { 
         // Display whether the page passed validation.
         if (Page.IsValid) 
         {
            Message.Text = "Page is valid.";
         }

         else 
         {
            Message.Text = "Page is not valid!";
         }
      }

      void ServerValidation(object source, ServerValidateEventArgs args)
      {
         try 
         {
            // Test whether the value entered into the text box is even.
            int i = int.Parse(args.Value);
            args.IsValid = ((i%2) == 0);
         }

         catch(Exception ex)
         {
            args.IsValid = false;
         }
      }
       
   </script>    

</head>
<body>

   <form id="Form1" runat="server">
  
      <h3>CustomValidator ServerValidate Example</h3>

      <asp:Label id="Message"  
           Text="Enter an even number:" 
           Font-Name="Verdana" 
           Font-Size="10pt" 
           runat="server"/>

      <p>

      <asp:TextBox id="Text1" 
           runat="server" />
    
        

      <asp:CustomValidator id="CustomValidator1"
           ControlToValidate="Text1"
           ClientValidationFunction="ClientValidate"
           OnServerValidate="ServerValidation"
           Display="Static"
           ErrorMessage="Not an even number!"
           ForeColor="green"
           Font-Name="verdana" 
           Font-Size="10pt"
           runat="server"/>

      <p>
 
      <asp:Button id="Button1"
           Text="Validate" 
           OnClick="ValidateBtn_OnClick" 
           runat="server"/>

   </form>
</body>
</html>

<script language="javascript"> 
   function ClientValidate(source, arguments)
   {
        if (arguments.Value % 2 == 0 ){
            arguments.IsValid = true;
        } else {
            arguments.IsValid = false;
        }
   }
</script>
<%@ Page Language="VB" AutoEventWireup="True" %>

<html>
<head>

   <script runat="server">

      Sub ValidateBtn_OnClick(sender As Object, e As EventArgs) 
           ' Display whether the page passed validation.
           If Page.IsValid Then
               Message.Text = "Page is valid."
           Else
               Message.Text = "Page is not valid!"
           End If
       End Sub

      Sub ServerValidation(source As Object, args As ServerValidateEventArgs)
           Try
               ' Test whether the value entered into the text box is even.
               Dim num As Integer = Integer.Parse(args.Value)
               args.IsValid = ((num Mod 2) = 0)
           Catch ex As Exception
               args.IsValid = False
           End Try
       End Sub

   </script>      

</head>
<body>

   <form id="Form1" runat="server">
  
      <h3>CustomValidator ServerValidate Example</h3>

      <asp:Label id="Message"  
           Text="Enter an even number:" 
           Font-Name="Verdana" 
           Font-Size="10pt" 
           runat="server"/>

      <p>

      <asp:TextBox id="Text1" 
           runat="server" />
    
        

      <asp:CustomValidator id="CustomValidator1"
           ControlToValidate="Text1"
           ClientValidationFunction="ClientValidate"
           OnServerValidate="ServerValidation"
           Display="Static"
           ErrorMessage="Not an even number!"
           ForeColor="green"
           Font-Name="verdana" 
           Font-Size="10pt"
           runat="server"/>

      <p>
 
      <asp:Button id="Button1"
           Text="Validate" 
           OnClick="ValidateBtn_OnClick" 
           runat="server"/>

   </form>
  
</body>
</html>

<script language="javascript">
   function ClientValidate(source, arguments)
   {
        if (arguments.Value % 2 == 0 ){
            arguments.IsValid = true;
        } else {
            arguments.IsValid = false;
        }
   }
</script>

설명

클라이언트 쪽 유효성 검사를 수행 하는 함수의 이름으로이 속성을 설정 합니다.

클라이언트 유효성 검사는 대상 브라우저에서 실행 하기 때문에 JScript 또는 VBScript와 같은 브라우저에서 지원 되는 스크립팅 언어를 사용 하 여 함수를 작성 되어야 합니다.

이 속성은 테마 또는 스타일시트 테마에 의해 설정될 수 없습니다. 자세한 내용은 ThemeableAttribute 하 고 ASP.NET 테마 및 스킨합니다.

적용 대상

추가 정보