ClientScriptManager.RegisterOnSubmitStatement(Type, String, String) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
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 특성에 대한 자세한 내용은 W3C(World Wide Web 컨소시엄) 웹 사이트를 참조하세요.