使用类型、键和脚本文本向
Page 对象注册 OnSubmit 语句。该语句在提交
HtmlForm 时执行。
命名空间: System.Web.UI
程序集: System.Web(在 system.web.dll 中)
Public Sub RegisterOnSubmitStatement ( _
type As Type, _
key As String, _
script As String _
)
Dim instance As ClientScriptManager
Dim type As Type
Dim key As String
Dim script As String
instance.RegisterOnSubmitStatement(type, key, script)
public void RegisterOnSubmitStatement (
Type type,
string key,
string script
)
public:
void RegisterOnSubmitStatement (
Type^ type,
String^ key,
String^ script
)
public void RegisterOnSubmitStatement (
Type type,
String key,
String script
)
public function RegisterOnSubmitStatement (
type : Type,
key : String,
script : String
)
参数
- type
要注册的 OnSubmit 语句的类型。
- key
要注册的 OnSubmit 语句的键。
- script
要注册的 OnSubmit 语句的脚本文本。
OnSubmit 语句由它的键和类型唯一标识。具有相同的键和类型的语句被视为重复语句。只有一个具有给定的类型和键对的语句可向该页面注册。试图注册一个已经注册的语句不会创建重复的语句。
调用 IsOnSubmitStatementRegistered 方法可确定某 OnSubmit 语句是否已通过给定的键/类型对注册,从而避免不必要地添加脚本的尝试。
RegisterOnSubmitStatement 方法的 script 参数可以包含多个脚本命令,只要它们以分号 (;) 正确地分隔。
RegisterOnSubmitStatement 添加一个脚本,该脚本在页面提交前执行并提供取消提交的机会。
有关 HTML 窗体和 OnSubmit 属性的更多信息,请参见万维网联合会 (W3C) 网站。
下面的代码示例演示 RegisterOnSubmitStatement 方法的用法。
<%@ 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 >
<head>
<title>ClientScriptManager Example</title>
</head>
<body>
<form id="Form1"
runat="server">
<input type="submit"
value="Submit" />
</form>
</body>
</html>
<%@ 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 >
<head>
<title>ClientScriptManager Example</title>
</head>
<body>
<form id="Form1"
runat="server">
<input type="submit"
value="Submit" />
</form>
</body>
</html>
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
Windows Vista、Microsoft Windows XP SP2 和 Windows Server 2003 SP1 支持 Microsoft .NET Framework 3.0。
.NET Framework
受以下版本支持:3.0、2.0