ClientScriptManager.RegisterOnSubmitStatement(Type, String, String) 메서드

정의

형식, 키 및 스크립트 리터럴을 사용하여 OnSubmit 문을 Page 개체에 등록합니다. 이 문은 HtmlForm을 전송할 때 실행됩니다.

public:
 void RegisterOnSubmitStatement(Type ^ type, System::String ^ key, System::String ^ script);
public void RegisterOnSubmitStatement (Type type, string key, string script);
member this.RegisterOnSubmitStatement : Type * string * string -> unit
Public Sub RegisterOnSubmitStatement (type As Type, key As String, script As String)

매개 변수

type
Type

등록할 OnSubmit 문의 형식입니다.

key
String

등록할 OnSubmit 문의 키입니다.

script
String

등록할 OnSubmit 문의 스크립트 리터럴입니다.

예외

type이(가) null인 경우

예제

다음 코드 예제에서는 RegisterOnSubmitStatement 메서드.

<%@ Page Language="C#"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
  public void Page_Load(Object sender, EventArgs e)
  {
    // Define the name and type of the client script on the page.
    String csname = "OnSubmitScript";
    Type cstype = this.GetType();
        
    // Get a ClientScriptManager reference from the Page class.
    ClientScriptManager cs = Page.ClientScript;

    // Check to see if the OnSubmit statement is already registered.
    if (!cs.IsOnSubmitStatementRegistered(cstype, csname))
    {
      String cstext = "document.write('Text from OnSubmit statement');";
      cs.RegisterOnSubmitStatement(cstype, csname, cstext);
    }

  }
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head>
    <title>ClientScriptManager Example</title>
  </head>
  <body>
     <form    id="Form1"
            runat="server">
     <input type="submit"
            value="Submit" />
     </form>
  </body>
</html>
<%@ Page Language="VB" %>

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

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

    ' Define the name and type of the client script on the page.
    Dim csname As String = "OnSubmitScript"
    Dim cstype As Type = Me.GetType()
    
    ' Get a ClientScriptManager reference from the Page class.
    Dim cs As ClientScriptManager = Page.ClientScript
    
    ' Check to see if the OnSubmit statement is already registered.
    If (Not cs.IsOnSubmitStatementRegistered(cstype, csname)) Then
      
      Dim cstext As String = "document.write('Text from OnSubmit statement.');"
      cs.RegisterOnSubmitStatement(cstype, csname, cstext)
      
    End If
    
  End Sub
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head>
    <title>ClientScriptManager Example</title>
  </head>
  <body>
     <form    id="Form1"
            runat="server">
     <input type="submit"
            value="Submit" />
     </form>
  </body>
</html>

설명

OnSubmit 문은 해당 키 및 해당 형식에 따라 고유 하 게 식별 됩니다. 동일한 키 및 유형으로 문은 중복으로 간주 됩니다. 페이지를 사용 하 여 지정 된 형식 및 키 쌍을 사용 하 여 문은 하나만 등록할 수 있습니다. 이미 등록 되어 있는 문을 등록 하는 동안 문의 중복을 만들지 않습니다.

호출 된 IsOnSubmitStatementRegistered 메서드는 OnSubmit 문이 지정한 키 및 유형 쌍으로 이미 등록 되어 있는지 여부를 확인 하 여 불필요 하 게 스크립트를 추가 하려는 시도 방지 합니다.

합니다 script 의 매개 변수는 RegisterOnSubmitStatement 메서드 세미콜론 (;)를 사용 하 여 제대로 구분 되는 여러 개의 스크립트 명령을 포함할 수 있습니다.

RegisterOnSubmitStatement 페이지가 제출 되 고 제출을 취소 하는 기회를 제공 하기 전에 실행 되는 스크립트를 추가 합니다.

HTML 폼에 대 한 자세한 내용은 및 OnSubmit 특성을 참조 합니다 World Wide Web Consortium (W3C) 웹 사이트합니다.

적용 대상

추가 정보