ScriptManager Class

Definition

为 Web 和应用程序服务管理 ASP.NET Ajax 脚本库和脚本文件、局部页面呈现以及客户端代理类生成。Manages ASP.NET Ajax script libraries and script files, partial-page rendering, and client proxy class generation for Web and application services.

public ref class ScriptManager : System::Web::UI::Control, System::Web::UI::IPostBackDataHandler, System::Web::UI::IPostBackEventHandler
[System.Drawing.ToolboxBitmap(typeof(EmbeddedResourceFinder), "System.Web.Resources.ScriptManager.bmp")]
public class ScriptManager : System.Web.UI.Control, System.Web.UI.IPostBackDataHandler, System.Web.UI.IPostBackEventHandler
type ScriptManager = class
    inherit Control
    interface IPostBackDataHandler
    interface IPostBackEventHandler
Public Class ScriptManager
Inherits Control
Implements IPostBackDataHandler, IPostBackEventHandler
Inheritance
ScriptManager
Attributes
Implements

Examples

下面的示例演示使用 ScriptManager 控件的不同方案。The following examples show different scenarios for using the ScriptManager control.

启用部分页面更新Enabling Partial-Page Updates

下面的示例演示如何使用 ScriptManager 控件启用部分页面更新。The following example shows how to use the ScriptManager control to enable partial-page updates. 在此示例中,CalendarDropDownList 控件位于 UpdatePanel 控件中。In this example, a Calendar and a DropDownList control are inside an UpdatePanel control. 默认情况下,将 AlwaysUpdateMode 属性的值,并 trueChildrenAsTriggers 属性的值。By default, the value of the UpdateMode property is Always, and the value of the ChildrenAsTriggers property is true. 因此,面板的子控件导致异步回发。Therefore, child controls of the panel cause an asynchronous postback.


<%@ 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">
    void DropDownSelection_Change(Object sender, EventArgs e)
    {
        Calendar1.DayStyle.BackColor =
            System.Drawing.Color.FromName(ColorList.SelectedItem.Value);
    }

    protected void Calendar1_SelectionChanged(object sender, EventArgs e)
    {
        SelectedDate.Text = 
            Calendar1.SelectedDate.ToString();
    }

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>UpdatePanel Example</title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:ScriptManager ID="ScriptManager1" 
                               runat="server" />
            <asp:UpdatePanel ID="UpdatePanel1"
                             runat="server">
                <ContentTemplate>
                    <asp:Calendar ID="Calendar1" 
                                  ShowTitle="True"
                                  OnSelectionChanged="Calendar1_SelectionChanged"
                                  runat="server" />
                    <div>
                        Background:
                        <br />
                        <asp:DropDownList ID="ColorList" 
                                          AutoPostBack="True" 
                                          OnSelectedIndexChanged="DropDownSelection_Change"
                                          runat="server">
                            <asp:ListItem Selected="True" Value="White"> 
                            White </asp:ListItem>
                            <asp:ListItem Value="Silver"> 
                            Silver </asp:ListItem>
                            <asp:ListItem Value="DarkGray"> 
                            Dark Gray </asp:ListItem>
                            <asp:ListItem Value="Khaki"> 
                            Khaki </asp:ListItem>
                            <asp:ListItem Value="DarkKhaki"> D
                            ark Khaki </asp:ListItem>
                        </asp:DropDownList>
                    </div>
                    <br />
                    Selected date:
                    <asp:Label ID="SelectedDate" 
                               runat="server">None.</asp:Label>
                </ContentTemplate>
            </asp:UpdatePanel>
            <br />
        </div>
    </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">
    Sub DropDownSelection_Change(ByVal Sender As Object, ByVal E As EventArgs)
        Calendar1.DayStyle.BackColor = _
        System.Drawing.Color.FromName(ColorList.SelectedItem.Value)
    End Sub

    Protected Sub Calendar1_SelectionChanged(ByVal Sender As Object, ByVal E As EventArgs)
        SelectedDate.Text = Calendar1.SelectedDate.ToString()
    End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>UpdatePanel Example</title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:ScriptManager ID="ScriptManager1" 
                               runat="server" />
            <asp:UpdatePanel ID="UpdatePanel1"
                             runat="server">
                <ContentTemplate>
                    <asp:Calendar ID="Calendar1" 
                                  ShowTitle="True"
                                  OnSelectionChanged="Calendar1_SelectionChanged"
                                  runat="server" />
                    <div>
                        Background:
                        <br />
                        <asp:DropDownList ID="ColorList" 
                                          AutoPostBack="True" 
                                          OnSelectedIndexChanged="DropDownSelection_Change"
                                          runat="server">
                            <asp:ListItem Selected="True" Value="White"> 
                            White </asp:ListItem>
                            <asp:ListItem Value="Silver"> 
                            Silver </asp:ListItem>
                            <asp:ListItem Value="DarkGray"> 
                            Dark Gray </asp:ListItem>
                            <asp:ListItem Value="Khaki"> 
                            Khaki </asp:ListItem>
                            <asp:ListItem Value="DarkKhaki"> D
                            ark Khaki </asp:ListItem>
                        </asp:DropDownList>
                    </div>
                    <br />
                    Selected date:
                    <asp:Label ID="SelectedDate" 
                               runat="server">None.</asp:Label>
                </ContentTemplate>
            </asp:UpdatePanel>
            <br />
        </div>
    </form>
</body>
</html>

处理部分页面更新错误并注册脚本Handling Partial-Page Update Errors and Registering Script

下面的示例演示如何在部分页面更新过程中提供自定义错误处理。The following example shows how to provide custom error handling during partial-page updates. 默认情况下,当在部分页更新期间发生错误时,将显示 JavaScript 消息框。By default, when an error occurs during partial-page updates, a JavaScript message box is displayed. 此示例演示如何通过为 AsyncPostBackError 事件提供处理程序,并在事件处理程序中设置 AsyncPostBackErrorMessage 属性,来使用自定义错误处理。This example demonstrates how to use custom error handling by providing a handler for the AsyncPostBackError event, and by setting the AsyncPostBackErrorMessage property in the event handler. 还可以设置 AllowCustomErrorsRedirect 属性,以指定在部分页面更新过程中发生错误时如何使用 Web.config 文件的自定义错误部分。You can also set the AllowCustomErrorsRedirect property to specify how the custom errors section of the Web.config file is used when an error occurs during partial-page updates. 在此示例中,将使用 AllowCustomErrorsRedirect 属性的默认值。In this example, the default value of the AllowCustomErrorsRedirect property is used. 这意味着,如果 web.config 文件包含customErrors元素,该元素将确定如何显示错误。This means that if the Web.config file contains a customErrors element, that element determines how errors are displayed. 有关详细信息,请参阅CustomErrors 元素(ASP.NET Settings Schema)For more information, see customErrors Element (ASP.NET Settings Schema).

<%@ 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">

    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            int a = Int32.Parse(TextBox1.Text);
            int b = Int32.Parse(TextBox2.Text);
            int res = a / b;
            Label1.Text = res.ToString();
        }
        catch (Exception ex)
        {
            if (TextBox1.Text.Length > 0 && TextBox2.Text.Length > 0)
            {
                ex.Data["ExtraInfo"] = " You can't divide " +
                    TextBox1.Text + " by " + TextBox2.Text + ".";
            }
            throw ex;
        }
    }

    protected void ScriptManager1_AsyncPostBackError(object sender, AsyncPostBackErrorEventArgs e)
    {
        if (e.Exception.Data["ExtraInfo"] != null)
        {
            ScriptManager1.AsyncPostBackErrorMessage =
                e.Exception.Message +
                e.Exception.Data["ExtraInfo"].ToString();
        }
        else
        {
            ScriptManager1.AsyncPostBackErrorMessage =
                "An unspecified error occurred.";
        }
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>UpdatePanel Error Handling Example</title>
    <style type="text/css">
    #UpdatePanel1 {
      width: 200px; height: 50px;
      border: solid 1px gray;
    }
    #AlertDiv{
    left: 40%; top: 40%;
    position: absolute; width: 200px;
    padding: 12px; 
    border: #000000 1px solid;
    background-color: white; 
    text-align: left;
    visibility: hidden;
    z-index: 99;
    }
    #AlertButtons{
    position: absolute; right: 5%; bottom: 5%;
    }
    </style>
</head>
<body id="bodytag">
    <form id="form1" runat="server">
        <div>
            <asp:ScriptManager ID="ScriptManager1" 
            OnAsyncPostBackError="ScriptManager1_AsyncPostBackError" runat="server" >
            <Scripts>
            <asp:ScriptReference Path="ErrorHandling.js" />
            </Scripts>
            </asp:ScriptManager>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Width="39px"></asp:TextBox>
                    /
                    <asp:TextBox ID="TextBox2" runat="server" Width="39px"></asp:TextBox>
                    =
                    <asp:Label ID="Label1" runat="server"></asp:Label><br />
                    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="calculate" />
                </ContentTemplate>
            </asp:UpdatePanel>
            <div id="AlertDiv">
                <div id="AlertMessage">
                </div>
                <br />
                <div id="AlertButtons">
                    <input id="OKButton" type="button" value="OK" runat="server" onclick="ClearErrorState()" />
                </div>
            </div>
        </div>
    </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 Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Try
            Dim a As Int32
            a = Int32.Parse(TextBox1.Text)
            Dim b As Int32
            b = Int32.Parse(TextBox2.Text)
            Dim res As Int32 = a / b
            Label1.Text = res.ToString()
        Catch ex As Exception
            If (TextBox1.Text.Length > 0 AndAlso TextBox2.Text.Length > 0) Then
                ex.Data("ExtraInfo") = " You can't divide " & _
                  TextBox1.Text & " by " & TextBox2.Text & "."
            End If
            Throw ex
        End Try

    End Sub
    Protected Sub ScriptManager1_AsyncPostBackError(ByVal sender As Object, ByVal e As System.Web.UI.AsyncPostBackErrorEventArgs)
        If (e.Exception.Data("ExtraInfo") <> Nothing) Then
            ScriptManager1.AsyncPostBackErrorMessage = _
               e.Exception.Message & _
               e.Exception.Data("ExtraInfo").ToString()
        Else
            ScriptManager1.AsyncPostBackErrorMessage = _
               "An unspecified error occurred."
        End If
    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>UpdatePanel Error Handling Example</title>
    <style type="text/css">
    #UpdatePanel1 {
      width: 200px; height: 50px;
      border: solid 1px gray;
    }
    #AlertDiv{
    left: 40%; top: 40%;
    position: absolute; width: 200px;
    padding: 12px; 
    border: #000000 1px solid;
    background-color: white; 
    text-align: left;
    visibility: hidden;
    z-index: 99;
    }
    #AlertButtons{
    position: absolute; right: 5%; bottom: 5%;
    }
    </style>
</head>
<body id="bodytag">
    <form id="form1" runat="server">
        <div>
            <asp:ScriptManager ID="ScriptManager1" 
            OnAsyncPostBackError="ScriptManager1_AsyncPostBackError" runat="server" >
            <Scripts>
            <asp:ScriptReference Path="ErrorHandling.js" />
            </Scripts>
            </asp:ScriptManager>

            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Width="39px"></asp:TextBox>
                    /
                    <asp:TextBox ID="TextBox2" runat="server" Width="39px"></asp:TextBox>
                    =
                    <asp:Label ID="Label1" runat="server"></asp:Label><br />
                    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="calculate" />
                </ContentTemplate>
            </asp:UpdatePanel>
            <div id="AlertDiv">
                <div id="AlertMessage">
                </div>
                <br />
                <div id="AlertButtons">
                    <input id="OKButton" type="button" value="OK" runat="server" onclick="ClearErrorState()" />
                </div>
            </div>
        </div>
    </form>
</body>
</html>

全球化浏览器中显示的日期和时间Globalizing the Date and Time That Are Displayed in the Browser

下面的示例演示如何设置 EnableScriptGlobalization 属性,以便客户端脚本可以在浏览器中显示特定于区域性的日期和时间。The following example shows how to set the EnableScriptGlobalization property so that client script can display a culture-specific date and time in the browser. 在此示例中, @ Page指令的 Culture 属性设置为 autoIn the example, the Culture attribute of the @ Page directive is set to auto. 因此,在当前浏览器设置中指定的第一种语言将确定页面的区域性和 UI 区域性。As a result, the first language that is specified in the current browser settings determines the culture and UI culture for the page. 有关详细信息,请参阅如何:为 ASP.NET 网页全球化设置区域性和 UI 区域性For more information, see How to: Set the Culture and UI Culture for ASP.NET Web Page Globalization.

<%@ Page Language="C#" Culture="auto" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Globalization Example</title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" EnableScriptGlobalization="true" runat="server">
        </asp:ScriptManager>
        <script type="text/javascript">
        function pageLoad() {
          Sys.UI.DomEvent.addHandler($get("Button1"), "click", formatDate);
        }
        function formatDate() {
          var d = new Date();
          try {
            $get('Label1').innerHTML = d.localeFormat("dddd, dd MMMM yyyy HH:mm:ss");
          }
          catch(e) {
            alert("Error:" + e.message);
          }
        }
        </script>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="False" UpdateMode="Conditional">
        <ContentTemplate>
        <asp:Panel ID="Panel1" runat="server" GroupingText="Update Panel">
        <asp:Button ID="Button1" runat="server" Text="Display Date" />

        <br />

        <asp:Label ID="Label1" runat="server"></asp:Label>
        </asp:Panel>
        </ContentTemplate>
        </asp:UpdatePanel>
    </form>
</body>
</html>
<%@ Page Language="VB" Culture="auto" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Globalization Example</title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" EnableScriptGlobalization="true" runat="server">
        </asp:ScriptManager>
        <script type="text/javascript">
        function pageLoad() {
          Sys.UI.DomEvent.addHandler($get("Button1"), "click", formatDate);
        }
        function formatDate() {
          var d = new Date();
          try {
            $get('Label1').innerHTML = d.localeFormat("dddd, dd MMMM yyyy HH:mm:ss");
          }
          catch(e) {
            alert("Error:" + e.message);
          }
        }
        </script>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="False" UpdateMode="Conditional">
        <ContentTemplate>
        <asp:Panel ID="Panel1" runat="server" GroupingText="Update Panel">
        <asp:Button ID="Button1" runat="server" Text="Display Date" />

        <br />

        <asp:Label ID="Label1" runat="server"></asp:Label>
        </asp:Panel>
        </ContentTemplate>
        </asp:UpdatePanel>
    </form>
</body>
</html>

Remarks

本主题内容:In this topic:

介绍Introduction

ScriptManager 控件是 ASP.NET 中 Ajax 功能的核心。The ScriptManager control is central to Ajax functionality in ASP.NET. 控件管理页面上的所有 ASP.NET Ajax 资源。The control manages all ASP.NET Ajax resources on a page. 这包括将 Microsoft Ajax Library 脚本下载到浏览器并协调通过使用 UpdatePanel 控件启用的部分页面更新。This includes downloading Microsoft Ajax Library scripts to the browser and coordinating partial-page updates that are enabled by using UpdatePanel controls. 此外,ScriptManager 控件使您能够执行以下操作:In addition, the ScriptManager control enables you to do the following:

  • 注册与部分页面更新兼容的脚本。Register script that is compatible with partial-page updates. 为了管理脚本和核心库之间的依赖关系,你注册的任何脚本都将加载到 Microsoft Ajax 库脚本之后。In order to manage dependencies between your script and the core library, any script that you register is loaded after the Microsoft Ajax Library script.

  • 指定发布或调试脚本是否发送到浏览器。Specify whether release or debug scripts are sent to the browser.

  • 通过向 ScriptManager 控件注册 Web 服务,提供对脚本中的 Web 服务方法的访问。Provide access to Web service methods from script by registering Web services with the ScriptManager control.

  • 通过向 ScriptManager 控件注册这些服务,提供对客户端脚本中的 ASP.NET authentication、role 和 profile 应用程序服务的访问权限。Provide access to ASP.NET authentication, role, and profile application services from client script by registering these services with the ScriptManager control.

  • 在浏览器中启用 ECMAScript (JavaScript)日期数字字符串函数的区域性特定显示。Enable culture-specific display of ECMAScript (JavaScript) Date, Number, and String functions in the browser.

  • 通过使用 ScriptReference 控件的 ResourceUICultures 属性,为嵌入的脚本文件或独立脚本文件访问本地化资源。Access localization resources for embedded script files or for stand-alone script files by using the ResourceUICultures property of the ScriptReference control.

  • 使用 ScriptManager 控件注册实现 IExtenderControlIScriptControl 接口的服务器控件,以便呈现客户端组件和行为所需的脚本。Register server controls that implement the IExtenderControl or IScriptControl interfaces with the ScriptManager control so that script required by client components and behaviors is rendered.

部分页呈现Partial-Page Rendering

ASP.NET 页支持部分页面呈现的能力由以下因素控制:The ability of an ASP.NET page to support partial-page rendering is controlled by the following factors:

可以在运行时或在页面的 Init 事件发生之前,重写 EnablePartialRendering 属性的值。You can override the value of the EnablePartialRendering property at run time during or before the page's Init event. 如果尝试在页面的 Init 事件发生后更改此属性,则会引发 InvalidOperationException 异常。If you try to change this property after the page's Init event has occurred, an InvalidOperationException exception is thrown.

支持部分页面呈现时,ScriptManager 控件将呈现脚本,以启用异步回发和部分页面更新。When partial-page rendering is supported, the ScriptManager control renders script to enable asynchronous postbacks and partial-page updates. 将使用 UpdatePanel 控件指定要更新的页面区域。The regions of the page to be updated are designated by using UpdatePanel controls. ScriptManager 控件处理异步回发并仅刷新必须更新的页面区域。The ScriptManager control handles the asynchronous postbacks and refreshes only the regions of the page that have to be updated. 有关部分页面呈现的详细信息,请参阅部分页呈现概述For more information about partial-page rendering, see Partial-Page Rendering Overview. 有关导致更新的条件的详细信息,请参阅UpdatePanel 控件概述For more information about the conditions that cause an update, see UpdatePanel Control Overview.

结合使用 ScriptManager 控件和母版页、用户控件和其他子组件Using the ScriptManager Control with Master Pages, User Controls, and Other Child Components

一页在其层次结构中只能包含一个 ScriptManager 控件。A page can contain only one ScriptManager control in its hierarchy. 若要在父页已有 ScriptManager 控件时为嵌套页、用户控件或组件注册服务和脚本,请使用 ScriptManagerProxy 控件。To register services and scripts for nested pages, user controls, or components when the parent page already has a ScriptManager control, use the ScriptManagerProxy control. 有关详细信息,请参阅将 UpdatePanel 控件与母版页一起使用For more information, see Using the UpdatePanel Control with Master Pages.

脚本管理和注册Script Management and Registration

利用 ScriptManager 控件,你可以注册随后呈现为页的一部分的脚本。The ScriptManager control enables you to register script that is then rendered as part of the page. ScriptManager 控件注册方法可分为以下三个类别:The ScriptManager control registration methods can be broken into the following three categories:

  • 保证在 Microsoft Ajax 库上维护脚本依赖项的注册方法。Registration methods that guarantee that script dependencies on the Microsoft Ajax Library are maintained.

  • 不依赖于 Microsoft Ajax 库,但与 UpdatePanel 控件兼容的注册方法。Registration methods that are not dependent on the Microsoft Ajax Library, but that are compatible with UpdatePanel controls.

  • 支持使用 UpdatePanel 控件的注册方法。Registration methods that support working with UpdatePanel controls.

有关如何在 ASP.NET 中创建和使用 Ajax 脚本的详细信息,请参阅使用 Microsoft Ajax Library 创建自定义客户端脚本For more information about how to create and use Ajax script in ASP.NET, see Creating Custom Client Script by Using the Microsoft Ajax Library.

注册依赖于 Microsoft Ajax 库的脚本Registering Script That Is Dependent on the Microsoft Ajax Library

你可以使用以下方法来注册脚本文件,以保证保留 Microsoft Ajax 库上的任何依赖项。You can use the following methods to register script files in a way that guarantees that any dependencies on the Microsoft Ajax Library are maintained.

方法Method 定义Definition
RegisterScriptControl 注册一个服务器控件,该控件实现用于定义sys.databases客户端对象的 IScriptControl 接口。Registers a server control that implements the IScriptControl interface that is used to define a Sys.Component client object. ScriptManager 控件呈现支持客户端对象的脚本。The ScriptManager control renders script that supports the client object.
RegisterExtenderControl 注册一个服务器控件,该控件实现用于定义sys.databases客户端对象的 IExtenderControl 接口。Registers a server control that implements the IExtenderControl interface that is used to define a Sys.Component client object. ScriptManager 控件呈现支持客户端对象的脚本。The ScriptManager control renders script that supports the client object.

注册部分页面更新兼容脚本Registering Partial-Page Update Compatible Scripts

你可以使用以下方法来注册不依赖于 Microsoft Ajax 库但与 UpdatePanel 控件兼容的脚本文件。You can use the following methods to register script files that are not dependent on the Microsoft Ajax Library but that are compatible with UpdatePanel controls. 这些方法与 ClientScriptManager 控件的类似方法相对应。These methods correspond to similar methods of the ClientScriptManager control. 如果要渲染要在 UpdatePanel 控件内使用的脚本,请确保调用 ScriptManager 控件的方法。If you are rendering script for use inside an UpdatePanel control, make sure that you call the methods of the ScriptManager control.

方法Method 定义Definition
RegisterArrayDeclaration 向 JavaScript 数组添加一个值。Adds a value to a JavaScript array. 如果数组不存在,则创建它。If the array does not exist, it is created.
RegisterClientScriptBlock 在页的打开 <form> 标记后呈现 script 元素。Renders a script element after the page's opening <form> tag. 此脚本指定为字符串参数。The script is specified as a string parameter.
RegisterClientScriptInclude 在页的打开 <form> 标记后呈现 script 元素。Renders a script element after the page's opening <form> tag. 脚本内容通过将 src 特性设置为指向脚本文件的 URL 来指定。The script content is specified by setting the src attribute to a URL that points to a script file.
RegisterClientScriptResource 在页的打开 <form> 标记后呈现 script 元素。Renders a script element after the page's opening <form> tag. 脚本内容是使用程序集中的资源名称指定的。The script content is specified with a resource name in an assembly. 通过调用从程序集检索命名脚本的 HTTP 处理程序,使用 URL 自动填充 src 特性。The src attribute is automatically populated with a URL by a call to an HTTP handler that retrieves the named script from the assembly.
RegisterExpandoAttribute 呈现指定控件的标记中的自定义名称/值特性对(expando)。Renders a custom name/value attribute pair (an expando) in the markup for a specified control.
RegisterHiddenField 呈现隐藏的字段。Renders a hidden field.
RegisterOnSubmitStatement 注册为响应 form 元素的 submit 事件而执行的脚本。Registers a script that is executed in response to the form element's submit event. onSubmit 特性引用指定脚本。The onSubmit attribute references the specified script.
RegisterStartupScript 在页面结束 </form> 标记之前呈现启动脚本块。Renders a startup script block just before the page's closing </form> tag. 要呈现的脚本指定为字符串参数。The script to render is specified as a string parameter.

注册方法时,为该脚本指定类型/密钥对。When you register methods, you specify a type/key pair for that script. 如果已注册了具有相同类型/密钥对的脚本,则不会注册新的脚本。If a script with the same type/key pair is already registered, a new script is not registered. 同样,如果使用已存在的类型/资源名称对注册脚本,则不会再次添加引用资源的 script 元素。Similarly, if you register a script with a type/resource name pair that already exists, the script element that references the resource is not added again. 在注册以前注册的属性的 expando 特性时,将引发异常。When you register an expando attribute of a previously registered attribute, an exception is thrown. 允许重复注册数组值。Duplicate registration of array values is allowed.

调用 RegisterClientScriptIncludeRegisterClientScriptResource 方法时,请避免注册执行内联函数的脚本。When you call the RegisterClientScriptInclude or the RegisterClientScriptResource method, avoid registering script that executes inline functions. 相反,注册包含函数定义(如事件处理程序)或应用程序的自定义类定义的脚本。Instead, register script that contains function definitions like event handlers or custom class definitions for your application.

UpdatePanel 控件的注册方法Registration Methods for UpdatePanel Controls

使用 UpdatePanel 控件时,可以使用以下方法自定义部分页面更新。You can use the following methods to customize partial-page updates when you use UpdatePanel controls.

方法Method 定义Definition
RegisterAsyncPostBackControl 将控件注册为异步回发的触发器。Registers a control as a trigger for asynchronous postbacks.
RegisterDataItem 在局部页面呈现期间将自定义数据发送到多个控件。Sends custom data to controls during partial-page rendering.
RegisterDispose 为位于 UpdatePanel 控件内的控件注册释放脚本。Registers a dispose script for a control that is inside an UpdatePanel control. 在更新或删除 UpdatePanel 控件时会执行脚本。The script is executed when the UpdatePanel control is updated or deleted. Dispose 方法用于作为 Microsoft Ajax 库一部分的客户端组件,并且在不再使用某个组件时必须释放资源。The dispose method is used for client components that are part of the Microsoft Ajax Library and that have to free resources when a component is no longer used.
RegisterPostBackControl 将控件注册为完全回发的触发器。Registers a control as a trigger for a full postback. 此方法用于 UpdatePanel 控件内执行异步回发的控件。This method is used for controls inside an UpdatePanel control that would otherwise perform asynchronous postbacks.

Web 服务引用Web Service References

可以通过创建 ServiceReference 对象并将其添加到 ScriptManager 控件的 Services 集合,来注册要从客户端脚本调用的 Web 服务。You can register a Web service to be called from client script by creating a ServiceReference object and adding it to the Services collection of the ScriptManager control. ASP.NET 为 Services 集合中的每个 ServiceReference 对象生成客户端代理对象。ASP.NET generates a client proxy object for each ServiceReference object in the Services collection. 可以通过编程方式将 ServiceReference 对象添加到 Services 集合,以便在运行时注册 Web 服务。You can programmatically add ServiceReference objects to the Services collection to register Web services at run time.

有关如何在脚本中访问 Web 服务的详细信息,请参阅在ASP.NET ajax 中向客户端脚本公开 Web 服务通过 ASP.NET AJAX 中的客户端脚本调用 web 服务For more information about how to access Web services in script, see Exposing Web Services to Client Script in ASP.NET AJAX and Calling Web Services from Client Script in ASP.NET AJAX.

本地化Localization

ScriptManager 控件在呈现的页面中生成指向相应的本地化脚本文件的引用,这些文件是嵌入在程序集或独立脚本文件中的脚本文件。The ScriptManager control generates references in the rendered page that point to the appropriate localized script files, which are either script files embedded in assemblies or stand-alone script files.

EnableScriptLocalization 属性设置为 true时,ScriptManager 控件将检索当前区域性的本地化资源(例如,本地化字符串)(如果存在)。When the EnableScriptLocalization property is set to true, the ScriptManager control retrieves localized resources (such as localized strings) for the current culture, if they exist. ScriptManager 控件为使用本地化资源提供了以下功能:The ScriptManager control provides the following functionality for using localized resources:

  • 嵌入在程序集中的脚本文件Script files that are embedded in an assembly. ScriptManager 控件确定要发送到浏览器的区域性特定或回退区域性脚本文件。The ScriptManager control determines which culture-specific or fallback-culture script file to send to the browser. 它通过使用特定于区域性的 NeutralResourcesLanguageAttribute 程序集特性、使用程序集打包的资源以及浏览器(如果有)的 UI 区域性来实现此功能。It does this by using the culture-specific NeutralResourcesLanguageAttribute assembly attribute, the resources packaged with the assembly, and the UI culture of the browser (if any).

  • 独立的脚本文件Stand-alone script files. ScriptManager 控件定义通过使用 ScriptReference 对象的 ResourceUICultures 属性支持的 UI 区域性列表。The ScriptManager control defines the list of UI cultures that are supported by using the ResourceUICultures property of the ScriptReference object.

  • 处于调试模式In debug mode. ScriptManager 控件尝试呈现包含调试信息的特定于区域性的脚本文件。The ScriptManager control tries to render a culture-specific script file that contains debug information. 例如,如果页处于调试模式,并且当前区域性设置为 en-MX,则该控件将呈现一个具有名称(scriptname如 en-MX)的脚本文件(如果该文件存在)。For example, if the page is in debug mode and the current culture is set to en-MX, the control renders a script file that has a name such as scriptname.en-MX.debug.js, if the file exists. 如果该文件不存在,则将呈现适当回退区域性的调试文件If the file does not exist, the debug file for the appropriate fallback culture is rendered

有关如何本地化资源的详细信息,请参阅为组件库本地化资源概述For more information about how to localize resources, see Localizing Resources for Component Libraries Overview.

错误处理Error Handling

当异步回发期间出现页面错误时,将引发 AsyncPostBackError 事件。When a page error occurs during asynchronous postbacks, the AsyncPostBackError event is raised. 将服务器上的错误发送到客户端的方式取决于 Web.config 文件的 AllowCustomErrorsRedirect 属性、AsyncPostBackErrorMessage 属性和自定义错误部分。The way in which errors on the server are sent to the client depends on the AllowCustomErrorsRedirect property, the AsyncPostBackErrorMessage property, and the custom errors section of the Web.config file. 有关详细信息,请参阅为 UpdatePanel 控件自定义错误处理For more information, see Customizing Error Handling for UpdatePanel Controls.

声明性语法Declarative Syntax

<asp:ScriptManager  
    AllowCustomErrorsRedirect="True|False"  
    AsyncPostBackErrorMessage="string"  
    AsyncPostBackTimeout="integer"  
    AuthenticationService-Path="uri"  
    EnablePageMethods="True|False"  
    EnablePartialRendering="True|False"  
    EnableScriptGlobalization="True|False"  
    EnableScriptLocalization="True|False"  
    EnableTheming="True|False"  
    EnableViewState="True|False"  
    ID="string"  
    LoadScriptsBeforeUI="True|False"  
    OnAsyncPostBackError="AsyncPostBackError event handler"  
    OnDataBinding="DataBinding event handler"  
    OnDisposed="Disposed event handler"  
    OnInit="Init event handler"  
    OnLoad="Load event handler"  
    OnPreRender="PreRender event handler"  
    OnResolveScriptReference="ResolveScriptReference event handler"  
    OnUnload="Unload event handler"  
    ProfileService-LoadProperties="string"  
    ProfileService-Path="uri"  
    RoleService-LoadRoles="True|False"  
    RoleService-Path="uri"  
    runat="server"  
    ScriptMode="Auto|Inherit|Debug|Release"  
    ScriptPath="string"  
    SkinID="string"  
    SupportsPartialRendering="True|False"  
    Visible="True|False"  
>  
        <AuthenticationService  
            Path="uri"  
        />  
        <ProfileService  
            LoadProperties="string"  
            Path="uri"  
        />  
        <RoleService  
            LoadRoles="True|False"  
            Path="uri"  
        />  
        <Scripts>  
            <asp:ScriptReference  
                Assembly="string"  
                IgnoreScriptPath="True|False"  
                Name="string"  
                NotifyScriptLoaded="True|False"  
                Path="string"  
                ResourceUICultures="string"  
                ScriptMode="Auto|Debug|Inherit|Release"  
            />  
        </Scripts>  
        <Services>  
            <asp:ServiceReference  
                InlineScript="True|False"  
                Path="string"  
            />  
        </Services>  
</asp:ScriptManager>  

Constructors

ScriptManager()

初始化 ScriptManager 类的新实例。Initializes a new instance of the ScriptManager class.

Properties

Adapter

获取控件的浏览器特定适配器。Gets the browser-specific adapter for the control.

(Inherited from Control)
AjaxFrameworkAssembly

获取页上组件所使用的 Ajax framework 程序集。Gets the Ajax framework assembly that components on the page use.

AjaxFrameworkMode

获取或设置一个值,该值指定将如何将 Microsoft Ajax 客户端库的客户端脚本包括到客户端上。Gets or sets a value that specifies how client scripts of the Microsoft Ajax client library will be included on the client.

AllowCustomErrorsRedirect

获取或设置一个值,该值确定异步回发出现错误时是否使用 Web.config 文件的自定义错误部分。Gets or sets a value that determines whether the custom errors section of the Web.config file is used during an error in an asynchronous postback.

AppRelativeTemplateSourceDirectory

获取或设置包含该控件的 PageUserControl 对象的应用程序相对虚拟目录。Gets or sets the application-relative virtual directory of the Page or UserControl object that contains this control.

(Inherited from Control)
AsyncPostBackErrorMessage

获取或设置异步回发期间发生未处理的服务器异常时发送到客户端的错误消息。Gets or sets the error message that is sent to the client when an unhandled server exception occurs during an asynchronous postback.

AsyncPostBackSourceElementID

获取引发异步回发的控件的唯一 ID。Gets the unique ID of the control that caused the asynchronous postback.

AsyncPostBackTimeout

获取或设置一个值,该值指示在未收到响应时异步回发超时前的时间(以秒为单位)。Gets or sets a value that indicates the time, in seconds, before asynchronous postbacks time out if no response is received.

AuthenticationService

获取与当前 AuthenticationServiceManager 实例关联的 ScriptManager 对象。Gets the AuthenticationServiceManager object that is associated with the current ScriptManager instance.

BindingContainer

获取包含该控件的数据绑定的控件。Gets the control that contains this control's data binding.

(Inherited from Control)
ChildControlsCreated

获取一个值,该值指示是否已创建服务器控件的子控件。Gets a value that indicates whether the server control's child controls have been created.

(Inherited from Control)
ClientID

获取由 ASP.NET 生成的 HTML 标记的控件 ID。Gets the control ID for HTML markup that is generated by ASP.NET.

(Inherited from Control)
ClientIDMode

获取或设置用于生成 ClientID 属性值的算法。Gets or sets the algorithm that is used to generate the value of the ClientID property.

(Inherited from Control)
ClientIDSeparator

获取一个字符值,该值表示 ClientID 属性中使用的分隔符字符。Gets a character value representing the separator character used in the ClientID property.

(Inherited from Control)
ClientNavigateHandler

获取或设置在客户端上处理 Sys.Application.navigate 事件的方法的名称。Gets or sets the name of the method that handles the Sys.Application.navigate event on the client.

CompositeScript

获取对支持网页的复合脚本的引用。Gets a reference to the composite script that supports the Web page.

Context

为当前 Web 请求获取与服务器控件关联的 HttpContext 对象。Gets the HttpContext object associated with the server control for the current Web request.

(Inherited from Control)
Controls

获取 ControlCollection 对象,该对象表示 UI 层次结构中的指定服务器控件的子控件。Gets a ControlCollection object that represents the child controls for a specified server control in the UI hierarchy.

(Inherited from Control)
DataItemContainer

如果命名容器实现 IDataItemContainer,则获取对命名容器的引用。Gets a reference to the naming container if the naming container implements IDataItemContainer.

(Inherited from Control)
DataKeysContainer

如果命名容器实现 IDataKeysControl,则获取对命名容器的引用。Gets a reference to the naming container if the naming container implements IDataKeysControl.

(Inherited from Control)
DesignMode

获取一个值,该值指示是否正在使用设计图面上的一个控件。Gets a value indicating whether a control is being used on a design surface.

(Inherited from Control)
EmptyPageUrl

获取或设置空白网页的 URL。Gets or sets a URL to a blank Web page.

EnableCdn

确定当前页是否从 CDN(内容分发网络)路径加载客户端脚本引用。Determines whether the current page loads client script references from CDN (Content Delivery Network) paths.

EnableCdnFallback

在无法访问 CDN(内容分发网络)的情况下启动脚本本地副本加载。Enables local copy of a script to load in the event that the CDN (Content Delivery Network) is unavailable.

EnableHistory

获取或设置一个值,该值指示网页是否支持历史时间点管理。Gets or sets a value that indicates whether the Web page supports history point management.

EnablePageMethods

获取或设置一个值,该值指示能否从客户端脚本调用 ASP.NET 页中公共静态页方法。Gets or sets a value that indicates whether public static page methods in an ASP.NET page can be called from client script.

EnablePartialRendering

获取或设置一个可部分呈现页面的值,该操作转而使你可以使用 UpdatePanel 控件来单独更新页面区域。Gets or sets a value that enables partial rendering of a page, which in turn enables you to update regions of the page individually by using UpdatePanel controls.

EnableScriptGlobalization

获取或设置一个值,该值指示 ScriptManager 控件是否呈现支持分析和格式化区域性特定的信息的脚本。Gets or sets a value that indicates whether the ScriptManager control renders script that supports parsing and formatting of culture-specific information.

EnableScriptLocalization

获取或设置一个值,该值指示 ScriptManager 控件是否呈现脚本文件的本地化版本。Gets or sets a value that indicates whether the ScriptManager control renders localized versions of script files.

EnableSecureHistoryState

获取或设置一个值,该值指示是否加密历史记录状态字符串。Gets or sets a value that indicates whether to encrypt the history state string.

EnableTheming

获取或设置一个值,该值指示主题是否应用于该控件。Gets or sets a value indicating whether themes apply to this control.

(Inherited from Control)
EnableViewState

获取或设置一个值,该值指示服务器控件是否向发出请求的客户端保持自己的视图状态以及它所包含的任何子控件的视图状态。Gets or sets a value indicating whether the server control persists its view state, and the view state of any child controls it contains, to the requesting client.

(Inherited from Control)
Events

获取控件的事件处理程序委托列表。Gets a list of event handler delegates for the control. 此属性为只读。This property is read-only.

(Inherited from Control)
HasChildViewState

获取一个值,该值指示当前服务器控件的子控件是否具有任何已保存的视图状态设置。Gets a value indicating whether the current server control's child controls have any saved view-state settings.

(Inherited from Control)
ID

获取或设置分配给服务器控件的编程标识符。Gets or sets the programmatic identifier assigned to the server control.

(Inherited from Control)
IdSeparator

获取用于分隔控件标识符的字符。Gets the character used to separate control identifiers.

(Inherited from Control)
IsChildControlStateCleared

获取一个值,该值指示该控件中包含的控件是否具有控件状态。Gets a value indicating whether controls contained within this control have control state.

(Inherited from Control)
IsDebuggingEnabled

获取一个值,它指示是否将呈现客户端脚本库的调试版本。Gets a value that indicates whether the debug versions of client script libraries will be rendered.

IsInAsyncPostBack

获取一个值,该值指示是否要在部分呈现模式下执行当前回发。Gets a value that indicates whether the current postback is being executed in partial-rendering mode.

IsNavigating

获取一个值,该值指示当前是否正在处理 Navigate 事件。Gets a value that indicates whether a Navigate event is currently being handled.

IsTrackingViewState

获取一个值,用于指示服务器控件是否会将更改保存到其视图状态中。Gets a value that indicates whether the server control is saving changes to its view state.

(Inherited from Control)
IsViewStateEnabled

获取一个值,该值指示是否为该控件启用了视图状态。Gets a value indicating whether view state is enabled for this control.

(Inherited from Control)
LoadScriptsBeforeUI

获取或设置一个值,该值指示是在加载页 UI 的标记之前还是在之后加载脚本。Gets or sets a value that indicates whether scripts are loaded before or after markup for the page UI is loaded.

LoadViewStateByID

获取一个值,该值指示控件是否通过 ID 而不是索引参与加载其视图状态。Gets a value indicating whether the control participates in loading its view state by ID instead of index.

(Inherited from Control)
NamingContainer

获取对服务器控件的命名容器的引用,此引用创建唯一的命名空间,以区分具有相同 ID 属性值的服务器控件。Gets a reference to the server control's naming container, which creates a unique namespace for differentiating between server controls with the same ID property value.

(Inherited from Control)
Page

获取对包含服务器控件的 Page 实例的引用。Gets a reference to the Page instance that contains the server control.

(Inherited from Control)
Parent

获取对页 UI 层次结构中服务器控件的父控件的引用。Gets a reference to the server control's parent control in the page control hierarchy.

(Inherited from Control)
ProfileService

获取与当前 ProfileServiceManager 实例关联的 ScriptManager 对象。Gets the ProfileServiceManager object that is associated with the current ScriptManager instance.

RenderingCompatibility

获取一个值,该值指定呈现的 HTML 将与之兼容的 ASP.NET 版本。Gets a value that specifies the ASP.NET version that rendered HTML will be compatible with.

(Inherited from Control)
RoleService

获取与当前 RoleServiceManager 实例关联的 ScriptManager 对象。Gets the RoleServiceManager object that is associated with the current ScriptManager instance.

ScriptMode

获取或设置一个值,该值指定是呈现客户端脚本库的调试版本还是发布版本。Gets or sets a value that specifies whether debug or release versions of client script libraries are rendered.

ScriptPath

获取或设置位置的根路径,该位置用来生成指向 ASP.NET Ajax 和自定义脚本文件的路径。Gets or sets the root path of the location that is used to build the paths to ASP.NET Ajax and custom script files.

ScriptResourceMapping

获取一个 ScriptResourceMapping 对象。Gets a ScriptResourceMapping object.

Scripts

获取一个包含 ScriptReferenceCollection 对象(每个对象表示一个呈现给客户端的脚本文件)的 ScriptReference 对象。Gets a ScriptReferenceCollection object that contains the ScriptReference objects, each of which represents a script file rendered to the client.

Services

获取一个 ServiceReferenceCollection 对象,该对象包含 ASP.NET 在客户端上针对 Ajax 功能公开的每个 Web 服务的 ServiceReference 对象。Gets a ServiceReferenceCollection object that contains a ServiceReference object for each Web service that ASP.NET exposes on the client for Ajax functionality.

Site

获取容器信息,该容器在呈现于设计图面上时承载当前控件。Gets information about the container that hosts the current control when rendered on a design surface.

(Inherited from Control)
SkinID

获取或设置要应用于控件的外观。Gets or sets the skin to apply to the control.

(Inherited from Control)
SupportsPartialRendering

获取一个指示客户端是否支持局部页面呈现的值。Gets a value that indicates whether the client supports partial-page rendering.

TemplateControl

获取或设置对包含该控件的模板的引用。Gets or sets a reference to the template that contains this control.

(Inherited from Control)
TemplateSourceDirectory

获取包含当前服务器控件的 PageUserControl 的虚拟目录。Gets the virtual directory of the Page or UserControl that contains the current server control.

(Inherited from Control)
UniqueID

获取服务器控件的唯一的、以分层形式限定的标识符。Gets the unique, hierarchically qualified identifier for the server control.

(Inherited from Control)
ValidateRequestMode

获取或设置指示控件是否检查来自浏览器的客户端输入是否具有潜在危险值的值。Gets or sets a value that indicates whether the control checks client input from the browser for potentially dangerous values.

(Inherited from Control)
ViewState

获取状态信息的字典,这些信息使您可以在同一页的多个请求间保存和还原服务器控件的视图状态。Gets a dictionary of state information that allows you to save and restore the view state of a server control across multiple requests for the same page.

(Inherited from Control)
ViewStateIgnoresCase

获取一个值,该值指示 StateBag 对象是否不区分大小写。Gets a value that indicates whether the StateBag object is case-insensitive.

(Inherited from Control)
ViewStateMode

获取或设置此控件的视图状态模式。Gets or sets the view-state mode of this control.

(Inherited from Control)
Visible

重写从 Visible 基类继承的 Control 属性以防止设置此值。Overrides the Visible property that is inherited from the base Control class to prevent setting this value.

Methods

AddedControl(Control, Int32)

在子控件添加到 Control 对象的 Controls 集合后调用。Called after a child control is added to the Controls collection of the Control object.

(Inherited from Control)
AddHistoryPoint(NameValueCollection, String)

使用指定的状态数据集合和状态标题创建历史时间点,然后将它添加到浏览器的历史记录堆栈中。Creates a history point and adds it to the browser's history stack, using the specified state data collection and state title.

AddHistoryPoint(String, String)

使用指定的状态键和状态值创建历史时间点,然后将它添加到浏览器的历史记录堆栈中。Creates a history point and adds it to the browser's history stack, using the specified state key and state value.

AddHistoryPoint(String, String, String)

使用指定的状态键、状态值和状态标题创建历史时间点,然后将它添加到浏览器的历史记录堆栈中。Creates a history point and adds it to the browser's history stack, using the specified state key, state value, and state title.

AddParsedSubObject(Object)

通知服务器控件,分析了一个元素(XML 或 HTML),并将该元素添加到服务器控件的 ControlCollection 对象中。Notifies the server control that an element, either XML or HTML, was parsed, and adds the element to the server control's ControlCollection object.

(Inherited from Control)
ApplyStyleSheetSkin(Page)

将页样式表中定义的样式属性应用到控件。Applies the style properties defined in the page style sheet to the control.

(Inherited from Control)
BeginRenderTracing(TextWriter, Object)

开始输出数据的设计时追踪。Begins design-time tracing of rendering data.

(Inherited from Control)
BuildProfileTree(String, Boolean)

收集有关服务器控件的信息并将该信息发送到 Trace 属性,在启用页的跟踪功能时将显示该属性。Gathers information about the server control and delivers it to the Trace property to be displayed when tracing is enabled for the page.

(Inherited from Control)
ClearCachedClientID()

将缓存的 ClientID 值设置为 nullSets the cached ClientID value to null.

(Inherited from Control)
ClearChildControlState()

删除服务器控件的子控件的控件状态信息。Deletes the control-state information for the server control's child controls.

(Inherited from Control)
ClearChildState()

删除服务器控件的所有子控件的视图状态和控件状态信息。Deletes the view-state and control-state information for all the server control's child controls.

(Inherited from Control)
ClearChildViewState()

删除服务器控件的所有子控件的视图状态信息。Deletes the view-state information for all the server control's child controls.

(Inherited from Control)
ClearEffectiveClientIDMode()

将当前控件实例和任何子控件的 ClientIDMode 属性设置为 InheritSets the ClientIDMode property of the current control instance and of any child controls to Inherit.

(Inherited from Control)
CreateChildControls()

由 ASP.NET 页框架调用,以通知服务器控件在准备回发或呈现时使用基于撰写的实现来创建其所包含任何子控件。Called by the ASP.NET page framework to notify server controls that use composition-based implementation to create any child controls they contain in preparation for posting back or rendering.

(Inherited from Control)
CreateControlCollection()

创建一个新 ControlCollection 对象来保存服务器控件的子控件(包括文本控件和服务器控件)。Creates a new ControlCollection object to hold the child controls (both literal and server) of the server control.

(Inherited from Control)
DataBind()

将数据源绑定到调用的服务器控件及其所有子控件。Binds a data source to the invoked server control and all its child controls.

(Inherited from Control)
DataBind(Boolean)

将数据源绑定到调用的服务器控件及其所有子控件,同时可以选择引发 DataBinding 事件。Binds a data source to the invoked server control and all its child controls with an option to raise the DataBinding event.

(Inherited from Control)
DataBindChildren()

将数据源绑定到服务器控件的子控件。Binds a data source to the server control's child controls.

(Inherited from Control)
Dispose()

使服务器控件得以在从内存中释放之前执行最后的清理操作。Enables a server control to perform final clean up before it is released from memory.

(Inherited from Control)
EndRenderTracing(TextWriter, Object)

结束输出数据的设计时追踪。Ends design-time tracing of rendering data.

(Inherited from Control)
EnsureChildControls()

确定服务器控件是否包含子控件。Determines whether the server control contains child controls. 如果不包含,则创建子控件。If it does not, it creates child controls.

(Inherited from Control)
EnsureID()

为尚未分配标识符的控件创建标识符。Creates an identifier for controls that do not have an identifier assigned.

(Inherited from Control)
Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
FindControl(String)

在当前的命名容器中搜索带指定 id 参数的服务器控件。Searches the current naming container for a server control with the specified id parameter.

(Inherited from Control)
FindControl(String, Int32)

使用指定的 idpathOffset 参数(该参数有助于搜索)中指定的整数在当前命名容器中搜索服务器控件。Searches the current naming container for a server control with the specified id and an integer, specified in the pathOffset parameter, which aids in the search. 不应重写此版本的 FindControl 方法。You should not override this version of the FindControl method.

(Inherited from Control)
Focus()

为控件设置输入焦点。Sets input focus to a control.

(Inherited from Control)
GetCurrent(Page)

获取给定 ScriptManager 对象的 Page 实例。Gets the ScriptManager instance for a given Page object.

GetDesignModeState()

获取控件的设计时数据。Gets design-time data for a control.

(Inherited from Control)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetRegisteredArrayDeclarations()

检索先前已向 Page 对象注册的 ECMAScript (JavaScript) 数组声明的只读集合。Retrieves a read-only collection of ECMAScript (JavaScript) array declarations that were previously registered with the Page object.

GetRegisteredClientScriptBlocks()

检索先前已向 ScriptManager 控件注册的客户端脚本块的只读集合。Retrieves a read-only collection of client script blocks that were previously registered with the ScriptManager control.

GetRegisteredDisposeScripts()

检索先前已向 dispose 对象注册的 Page 脚本的只读集合。Retrieves a read-only collection of dispose scripts that were previously registered with the Page object.

GetRegisteredExpandoAttributes()

检索先前已向 Page 对象注册的自定义 (expando) 特性的只读集合。Retrieves a read-only collection of custom (expando) attributes that were previously registered with the Page object.

GetRegisteredHiddenFields()

检索先前已向 Page 对象注册的隐藏字段的只读集合。Retrieves a read-only collection of hidden fields that were previously registered with the Page object.

GetRegisteredOnSubmitStatements()

检索先前已向 onsubmit 对象注册的 Page 语句的只读集合。Retrieves a read-only collection of onsubmit statements that were previously registered with the Page object.

GetRegisteredStartupScripts()

检索先前已向 Page 对象注册的启动脚本的只读集合。Retrieves a read-only collection of startup scripts that were previously registered with the Page object.

GetRouteUrl(Object)

获取与一组路由参数对应的 URL。Gets the URL that corresponds to a set of route parameters.

(Inherited from Control)
GetRouteUrl(RouteValueDictionary)

获取与一组路由参数对应的 URL。Gets the URL that corresponds to a set of route parameters.

(Inherited from Control)
GetRouteUrl(String, Object)

获取与一组路由参数以及某个路由名称对应的 URL。Gets the URL that corresponds to a set of route parameters and a route name.

(Inherited from Control)
GetRouteUrl(String, RouteValueDictionary)

获取与一组路由参数以及某个路由名称对应的 URL。Gets the URL that corresponds to a set of route parameters and a route name.

(Inherited from Control)
GetStateString()

检索包含表示网页状态的键/值对的字符串。Retrieves a string that contains key/value pairs that represent the state of the Web page.

GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
GetUniqueIDRelativeTo(Control)

返回指定控件的 UniqueID 属性的前缀部分。Returns the prefixed portion of the UniqueID property of the specified control.

(Inherited from Control)
HasControls()

确定服务器控件是否包含任何子控件。Determines if the server control contains any child controls.

(Inherited from Control)
HasEvents()

返回一个值,该值指示是否为控件或任何子控件注册事件。Returns a value indicating whether events are registered for the control or any child controls.

(Inherited from Control)
IsLiteralContent()

确定服务器控件是否只包含文字内容。Determines if the server control holds only literal content.

(Inherited from Control)
LoadControlState(Object)

SaveControlState() 方法保存的上一个页请求还原控件状态信息。Restores control-state information from a previous page request that was saved by the SaveControlState() method.

(Inherited from Control)
LoadPostData(String, NameValueCollection)

读取从浏览器发送到服务器的表单数据,并确定异步回发的源。Reads form data that is posted from the browser to the server, and determines the source of the asynchronous postback.

LoadViewState(Object)

从用 SaveViewState() 方法保存的上一个页面请求还原视图状态信息。Restores view-state information from a previous page request that was saved by the SaveViewState() method.

(Inherited from Control)
MapPathSecure(String)

检索虚拟路径(绝对的或相对的)映射到的物理路径。Retrieves the physical path that a virtual path, either absolute or relative, maps to.

(Inherited from Control)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
OnAsyncPostBackError(AsyncPostBackErrorEventArgs)

引发 AsyncPostBackError 事件。Raises the AsyncPostBackError event.

OnBubbleEvent(Object, EventArgs)

确定服务器控件的事件是否沿页的 UI 服务器控件层次结构向上传递。Determines whether the event for the server control is passed up the page's UI server control hierarchy.

(Inherited from Control)
OnDataBinding(EventArgs)

引发 DataBinding 事件。Raises the DataBinding event.

(Inherited from Control)
OnInit(EventArgs)

引发 Init 事件并确保页面上只有一个 ScriptManager 控件。Raises the Init event and makes sure that only one ScriptManager control exists on the page.

OnLoad(EventArgs)

引发 Load 事件。Raises the Load event.

(Inherited from Control)
OnPreRender(EventArgs)

引发 PreRender 事件,并为部分页面更新注册脚本文件和服务。Raises the PreRender event, and registers script files and services for partial-page updates.

OnResolveCompositeScriptReference(CompositeScriptReferenceEventArgs)

引发 ResolveCompositeScriptReference 事件。Raises the ResolveCompositeScriptReference event.

OnResolveScriptReference(ScriptReferenceEventArgs)

ResolveScriptReference 控件托管的每个脚本引用引发 ScriptManager 事件。Raises the ResolveScriptReference event for each script reference that is managed by the ScriptManager control.

OnUnload(EventArgs)

引发 Unload 事件。Raises the Unload event.

(Inherited from Control)
OpenFile(String)

获取用于读取文件的 StreamGets a Stream used to read a file.

(Inherited from Control)
RaiseBubbleEvent(Object, EventArgs)

将所有事件源及其信息分配给控件的父级。Assigns any sources of the event and its information to the control's parent.

(Inherited from Control)
RaisePostBackEvent(String)

处理由 ScriptManager 控件引发的回发事件,并加载网页的历史记录状态。Processes a postback event raised by the ScriptManager control and loads the history state of the Web page.

RaisePostDataChangedEvent()

ScriptManager 控件回发到服务器时引发此控件的事件。Raises events for the ScriptManager control when it posts back to the server.

RegisterArrayDeclaration(Control, String, String)

ScriptManager 控件注册一个 ECMAScript (JavaScript) 数组声明以与 UpdatePanel 控件内的某个控件一起使用,并将此数组添加到页面中。Registers an ECMAScript (JavaScript) array declaration with the ScriptManager control for use with a control that is inside an UpdatePanel control, and adds the array to the page.

RegisterArrayDeclaration(Page, String, String)

ScriptManager 控件注册一个 ECMAScript (JavaScript) 数组声明以与 UpdatePanel 控件内的某个控件一起使用,并将此数组添加到页面中。Registers an ECMAScript (JavaScript) array declaration with the ScriptManager control for use with a control that is inside an UpdatePanel control, and adds the array to the page.

RegisterAsyncPostBackControl(Control)

将控件注册为异步回发的触发器。Registers a control as a trigger for asynchronous postbacks.

RegisterClientScriptBlock(Control, Type, String, String, Boolean)

ScriptManager 控件注册一个客户端脚本块以与 UpdatePanel 控件中的某个控件一起使用,然后将该此脚本块添加到页面中。Registers a client script block with the ScriptManager control for use with a control that is inside an UpdatePanel control, and then adds the script block to the page.

RegisterClientScriptBlock(Page, Type, String, String, Boolean)

ScriptManager 控件注册一个客户端脚本块以与 UpdatePanel 控件中的某个控件一起使用,然后将该此脚本块添加到页面中。Registers a client script block with the ScriptManager control for use with a control that is inside an UpdatePanel control, and then adds the script block to the page.

RegisterClientScriptInclude(Control, Type, String, String)

ScriptManager 控件注册一个客户端脚本文件,以便和 UpdatePanel 控件中的某个控件一起使用,然后将脚本文件引用添加到页面中。Registers a client script file with the ScriptManager control for use with a control that is inside an UpdatePanel control, and then adds a script file reference to the page.

RegisterClientScriptInclude(Page, Type, String, String)

每次发生异步回发时都向 ScriptManager 控件注册客户端脚本,然后将一个脚本文件引用添加到页面中。Registers client script with the ScriptManager control every time that an asynchronous postback occurs, and then adds a script file reference to the page.

RegisterClientScriptResource(Control, Type, String)

ScriptManager 控件注册嵌入程序集中的客户端脚本,以便和正在参与局部页面呈现的控件一起使用。Registers the client script that is embedded in an assembly with the ScriptManager control for use with a control that is participating in partial-page rendering.

RegisterClientScriptResource(Page, Type, String)

每次发生回发时都向 ScriptManager 控件注册嵌入程序集中的客户端脚本文件。Registers a client script file that is embedded in an assembly with the ScriptManager control every time that a postback occurs.

RegisterDataItem(Control, String)

在局部页面呈现期间将自定义数据发送到某个控件。Sends custom data to a control during partial-page rendering.

RegisterDataItem(Control, String, Boolean)

在局部页面呈现期间,将自定义数据发送到某个控件,并指示数据是否为 JavaScript 对象表示法 (JSON) 格式。Sends custom data to a control during partial-page rendering, and indicates whether the data is in JavaScript Object Notation (JSON) format.

RegisterDispose(Control, String)

dispose 控件内的某个控件注册一个 UpdatePanel 脚本。Registers a dispose script for a control that is inside an UpdatePanel control. 在更新或删除 UpdatePanel 控件时会执行脚本。The script is executed when the UpdatePanel control is updated or deleted.

RegisterExpandoAttribute(Control, String, String, String, Boolean)

ScriptManager 控件中,将名称/值对注册为指定控件的自定义 (expando) 特性。Registers a name/value pair with the ScriptManager control as a custom (expando) attribute of a specified control.

RegisterExtenderControl<TExtenderControl>(TExtenderControl, Control)

向当前 ScriptManager 实例注册扩展程序控件。Registers an extender control with the current ScriptManager instance.

RegisterHiddenField(Control, String, String)

针对 ScriptManager 控件内的控件,向 UpdatePanel 控件注册隐藏字段。Registers a hidden field with the ScriptManager control for a control that is inside an UpdatePanel control.

RegisterHiddenField(Page, String, String)

在每次异步回发期间向 ScriptManager 控件注册隐藏字段。Registers a hidden field with the ScriptManager control during every asynchronous postback.

RegisterNamedClientScriptResource(Control, String)

按资源名称向 ScriptManager 控件注册嵌入程序集中的客户端脚本,以便和正在参与局部页面呈现的控件一起使用。Registers client script by resource name that is embedded in an assembly with the ScriptManager control for use with a control that is participating in partial-page rendering.

RegisterNamedClientScriptResource(Page, String)

按资源名称向 ScriptManager 控件注册嵌入程序集中的客户端脚本,以便和正在参与局部页面呈现的控件一起使用。Registers client script by resource name that is embedded in an assembly with the ScriptManager control for use with a control that is participating in partial-page rendering.

RegisterOnSubmitStatement(Control, Type, String, String)

针对与 ScriptManager 控件一起使用的控件,向 UpdatePanel 控件注册提交表单时执行的 ECMAScript (JavaScript) 代码。Registers ECMAScript (JavaScript) code with the ScriptManager control for a control that is used with an UpdatePanel control that is executed when the form is submitted.

RegisterOnSubmitStatement(Page, Type, String, String)

针对与 ScriptManager 控件一起使用的控件,向 UpdatePanel 控件注册提交表单时执行的 ECMAScript (JavaScript) 代码。Registers ECMAScript (JavaScript) code with the ScriptManager control for a control that is used with an UpdatePanel control that is executed when the form is submitted.

RegisterPostBackControl(Control)

将控件注册为回发的触发器。Registers a control as a trigger for a postback. 此方法用于配置 UpdatePanel 控件内的回发控件,若未配置,此控件将执行异步回发。This method is used to configure postback controls inside an UpdatePanel control that would otherwise perform asynchronous postbacks.

RegisterScriptControl<TScriptControl>(TScriptControl)

向当前 ScriptManager 实例注册脚本控件。Registers a script control with the current ScriptManager instance.

RegisterScriptDescriptors(IExtenderControl)

回调到 ExtenderControl 类以返回为支持表示客户端控件、组件或行为的客户端对象而必须呈现的实例脚本。Calls back to an ExtenderControl class to return instance scripts that must be rendered to support the client object that represents a client control, component, or behavior.

RegisterScriptDescriptors(IScriptControl)

调用 ScriptControl 类以返回为支持表示客户端控件、组件或行为的客户端对象而必须呈现的实例脚本。Calls a ScriptControl class to return instance scripts that must be rendered to support the client object that represents a client control, component, or behavior.

RegisterStartupScript(Control, Type, String, String, Boolean)

使用 UpdatePanel 控件为 ScriptManager 中的某个控件注册一个启动脚本块,并将此脚本块添加到页面中。Registers a startup script block for a control that is inside an UpdatePanel by using the ScriptManager control, and adds the script block to the page.

RegisterStartupScript(Page, Type, String, String, Boolean)

为每个异步回发向 ScriptManager 控件注册一个启动脚本块,并将此脚本块添加到页面中。Registers a startup script block for every asynchronous postback with the ScriptManager control and adds the script block to the page.

RemovedControl(Control)

Control 对象的 Controls 集合移除子控件后调用。Called after a child control is removed from the Controls collection of the Control object.

(Inherited from Control)
Render(HtmlTextWriter)

使用指定的 ScriptManager 对象将 HtmlTextWriter 控件的内容呈现给浏览器。Renders the ScriptManager control's content to the browser by using the specified HtmlTextWriter object.

RenderChildren(HtmlTextWriter)

将服务器控件子级的内容输出到提供的 HtmlTextWriter 对象,该对象可写入要在客户端上呈现的内容。Outputs the content of a server control's children to a provided HtmlTextWriter object, which writes the content to be rendered on the client.

(Inherited from Control)
RenderControl(HtmlTextWriter)

将服务器控件内容输出到所提供的 HtmlTextWriter 对象,如果启用了跟踪,则还将存储有关该控件的跟踪信息。Outputs server control content to a provided HtmlTextWriter object and stores tracing information about the control if tracing is enabled.

(Inherited from Control)
RenderControl(HtmlTextWriter, ControlAdapter)

使用提供的 HtmlTextWriter 对象将服务器控件内容输出到提供的 ControlAdapter 对象。Outputs server control content to a provided HtmlTextWriter object using a provided ControlAdapter object.

(Inherited from Control)
ResolveAdapter()

获取负责呈现指定控件的控件适配器。Gets the control adapter responsible for rendering the specified control.

(Inherited from Control)
ResolveClientUrl(String)

获取浏览器可以使用的 URL。Gets a URL that can be used by the browser.

(Inherited from Control)
ResolveUrl(String)

将 URL 转换为在请求客户端可用的 URL。Converts a URL into one that is usable on the requesting client.

(Inherited from Control)
SaveControlState()

保存将页面回发到服务器之后发生的所有服务器控件状态更改。Saves any server control state changes that have occurred since the time the page was posted back to the server.

(Inherited from Control)
SaveViewState()

保存将页面回发到服务器之后发生的所有服务器控件视图状态更改。Saves any server control view-state changes that have occurred since the time the page was posted back to the server.

(Inherited from Control)
SetDesignModeState(IDictionary)

为控件设置设计时数据。Sets design-time data for a control.

(Inherited from Control)
SetFocus(Control)

将浏览器焦点设置为指定控件。Sets the browser focus to the specified control.

SetFocus(String)

将浏览器焦点设置为由 ID 指定的控件。Sets the browser focus to the control specified by ID.

SetRenderMethodDelegate(RenderMethod)

分配事件处理程序委托,以将服务器控件及其内容呈现到父控件中。Assigns an event handler delegate to render the server control and its content into its parent control.

(Inherited from Control)
SetTraceData(Object, Object)

使用跟踪数据键和跟踪数据值,为呈现数据的设计时追踪设置跟踪数据。Sets trace data for design-time tracing of rendering data, using the trace data key and the trace data value.

(Inherited from Control)
SetTraceData(Object, Object, Object)

使用跟踪对象、跟踪数据键和跟踪数据值,为呈现数据的设计时追踪设置跟踪数据。Sets trace data for design-time tracing of rendering data, using the traced object, the trace data key, and the trace data value.

(Inherited from Control)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)
TrackViewState()

导致跟踪服务器控件的视图状态的更改,以便这些更改可以存储到服务器控件的 StateBag 对象中。Causes tracking of view-state changes to the server control so they can be stored in the server control's StateBag object. 通过 ViewState 属性可访问此对象。This object is accessible through the ViewState property.

(Inherited from Control)

Events

AsyncPostBackError

当异步回发期间出现页面错误时发生。Occurs when there is a page error during an asynchronous postback.

DataBinding

当服务器控件绑定到数据源时发生。Occurs when the server control binds to a data source.

(Inherited from Control)
Disposed

当从内存释放服务器控件时发生,这是请求 ASP.NET 页时服务器控件生存期的最后阶段。Occurs when a server control is released from memory, which is the last stage of the server control lifecycle when an ASP.NET page is requested.

(Inherited from Control)
Init

当服务器控件初始化时发生;初始化是控件生存期的第一步。Occurs when the server control is initialized, which is the first step in its lifecycle.

(Inherited from Control)
Load

当服务器控件加载到 Page 对象中时发生。Occurs when the server control is loaded into the Page object.

(Inherited from Control)
Navigate

当用户点击浏览器的“后退”或“前进”按钮时发生。Occurs when the user clicks the browser's Back or Forward button.

PreRender

在加载 Control 对象之后、呈现之前发生。Occurs after the Control object is loaded but prior to rendering.

(Inherited from Control)
ResolveCompositeScriptReference

在向 ScriptManager 控件注册复合脚本时发生。Occurs when a composite script is registered with the ScriptManager control.

ResolveScriptReference

在向 Scripts 控件注册 ScriptManager 集合的成员时发生。Occurs when a member of the Scripts collection is registered with the ScriptManager control.

Unload

当服务器控件从内存中卸载时发生。Occurs when the server control is unloaded from memory.

(Inherited from Control)

Explicit Interface Implementations

IControlBuilderAccessor.ControlBuilder

有关此成员的说明,请参见 ControlBuilderFor a description of this member, see ControlBuilder.

(Inherited from Control)
IControlDesignerAccessor.GetDesignModeState()

有关此成员的说明,请参见 GetDesignModeState()For a description of this member, see GetDesignModeState().

(Inherited from Control)
IControlDesignerAccessor.SetDesignModeState(IDictionary)

有关此成员的说明,请参见 SetDesignModeState(IDictionary)For a description of this member, see SetDesignModeState(IDictionary).

(Inherited from Control)
IControlDesignerAccessor.SetOwnerControl(Control)

有关此成员的说明,请参见 SetOwnerControl(Control)For a description of this member, see SetOwnerControl(Control).

(Inherited from Control)
IControlDesignerAccessor.UserData

有关此成员的说明,请参见 UserDataFor a description of this member, see UserData.

(Inherited from Control)
IDataBindingsAccessor.DataBindings

有关此成员的说明,请参见 DataBindingsFor a description of this member, see DataBindings.

(Inherited from Control)
IDataBindingsAccessor.HasDataBindings

有关此成员的说明,请参见 HasDataBindingsFor a description of this member, see HasDataBindings.

(Inherited from Control)
IExpressionsAccessor.Expressions

有关此成员的说明,请参见 ExpressionsFor a description of this member, see Expressions.

(Inherited from Control)
IExpressionsAccessor.HasExpressions

有关此成员的说明,请参见 HasExpressionsFor a description of this member, see HasExpressions.

(Inherited from Control)
IParserAccessor.AddParsedSubObject(Object)

有关此成员的说明,请参见 AddParsedSubObject(Object)For a description of this member, see AddParsedSubObject(Object).

(Inherited from Control)
IPostBackDataHandler.LoadPostData(String, NameValueCollection)

有关此成员的说明,请参阅 LoadPostData(String, NameValueCollection)For a description of this member, see LoadPostData(String, NameValueCollection).

IPostBackDataHandler.RaisePostDataChangedEvent()

有关此成员的说明,请参阅 RaisePostDataChangedEvent()For a description of this member, see RaisePostDataChangedEvent().

IPostBackEventHandler.RaisePostBackEvent(String)

启用 ScriptManager 控件以处理回发事件,并加载网页的历史记录状态。Enables the ScriptManager control to process a postback event and load the history state of the Web page.

Extension Methods

FindDataSourceControl(Control)

返回与指定控件的数据控件关联的数据源。Returns the data source that is associated with the data control for the specified control.

FindFieldTemplate(Control, String)

返回指定控件的命名容器中指定列的字段模板。Returns the field template for the specified column in the specified control's naming container.

FindMetaTable(Control)

返回包含数据控件的元表对象。Returns the metatable object for the containing data control.

Applies to

See also