ScriptManager Control Overview
The ScriptManager control manages client script for AJAX-enabled ASP.NET Web pages.By default, the ScriptManager control registers the script for the Microsoft AJAX Library with the page.This enables client script to use the type system extensions and to support features such as partial-page rendering and Web-service calls.
Este tópico contém as seções a seguir:
Cenários
Segundo plano
Exemplos de código
Referência de Classe
Cenários
You must use a ScriptManager control on a page to enable the following AJAX features of ASP.NET:
Funcionalidade de script de cliente do Microsoft AJAX Librarye qualquer script personalizado que você deseja enviar para o navegador. Para obter mais informações, consulte Criando Scripts de Cliente Personalizado Usando a Biblioteca Microsoft AJAX.
Partial-page rendering, which enables regions on the page to be independently refreshed without a postback.The ASP.NET UpdatePanel, UpdateProgress, and Timer controls require a ScriptManager control in order to support partial-page rendering.
JavaScript proxy classes for Web services, which enable you to use client script to access Web services and specially marked methods in ASP.NET pages.It does this by exposing the Web services and page methods as strongly typed objects.
JavaScript classes to access ASP.NET authentication, profile, and roles application services.
Segundo plano
When a page contains one or more UpdatePanel controls, the ScriptManager control manages partial-page rendering in the browser.The control interacts with the page life cycle to update the parts of the page that are inside UpdatePanel controls.Para obter mais informações, consulte Visão geral de renderização de página parcial.
The EnablePartialRendering property of the ScriptManager control determines whether a page participates in partial-page updates.By default, the EnablePartialRendering property is true.Therefore, by default partial-page rendering is enabled when you add a ScriptManager control to the page.For information about how to use the UpdatePanel control with the ScriptManager control, see Introdução ao Controle UpdatePanel and Creating a Simple ASP.NET Page with Multiple UpdatePanel Controls.
Handling Partial-page Rendering Errors
During partial-page rendering, you can handle errors by doing the following:
Defina a propriedade AllowCustomErrorsRedirect.This determines how the custom error section of the Web.config file is used when an error occurs during an asynchronous postback.
Handle the ScriptManager control's AsyncPostBackError event, which is raised when there is a page error during an asynchronous postback.
Set the AsyncPostBackErrorMessage property, which is the error message that is sent to the browser.
Using Type System Extensions
The Microsoft AJAX Library adds type-system extensions to JavaScript that provide namespaces, inheritance, interfaces, enumerations, reflection, and helper functions for strings and arrays.These extensions provide functionality in client script that is like that of the .NET Framework.Eles permitem escrever aplicativos habilitados para AJAX ASP.NET de maneira estruturada que melhora a capacidade de manutenção, facilita a adição de recursos e facilita a funcionalidade da camada. Adicionando um ScriptManager controle a uma página da Web do ASP.NET inclui automaticamente as extensões de tipo do sistema para que você pode usar a biblioteca no script de cliente. Para obter mais informações, consulte Criando Scripts de Cliente Personalizado Usando a Biblioteca Microsoft AJAX.
Registering Custom Script
Use the ScriptManager control to manage resources that you have created for controls that participate in partial-page updates.Resources include scripts, styles, hidden fields, and arrays.The Scripts collection of the ScriptManager control contains a ScriptReference object for each script that is available to the browser.You can specify the scripts declaratively or programmatically.
The ScriptManager control also exposes registration methods that you can use to manage client script and hidden fields programmatically.When you are registering script or hidden fields that support partial-page updates, you must call registration methods of the ScriptManager control.(To register scripts that are not needed for partial-page updates, you use methods of the ClientScriptManager class.)
Observação: |
---|
Any scripts on the page that are registered by using the ScriptManager control and all event-handling script must be inside the form element on the page.Otherwise the script will not be registered or executed. |
For a list of the ClientScriptManager controls registration methods, see Criando Scripts de Cliente Personalizado Usando a Biblioteca Microsoft AJAX and the ClientScriptManager class overview.
Registering Web Services
Para registrar um serviço Web que você deseja chamar a partir de uma página ASP.NET habilitado por AJAX, você deve registrar serviço Web adicionando-o ScriptManager do controle Services coleção. The ASP.NET AJAX framework generates a client proxy object for each ServiceReference object in the Services collection.The proxy classes and their strongly typed members simplify using Web services from client script.
You can programmatically add ServiceReference objects to the Services collection to register Web services at run time.Para obter mais informações, consulte Serviços Web em ASP.NET AJAX.
Using Authentication, Profile, and Role Services from Client Script
The Microsoft AJAX Library includes proxy classes for calling the ASP.NET 2.0 forms authentication, profile, and roles application services directly from JavaScript.If you want to use a custom authentication service, you can register it by using the ScriptManager control.Para obter mais informações, consulte Usando Formulários de Autenticação com AJAX do ASP.NET, Usando Perfis de Informações com AJAX do ASP.NET e Usando Funções de Informações com AJAX do ASP.NET.
The ScriptManagerProxy Class
Only one instance of the ScriptManager control can be added to the page.The page can include the control directly, or indirectly inside a nested component such as a user control, content page for a master page, or nested master page.If a page already contains a ScriptManager control, but a nested or parent component needs additional features of the ScriptManager control, the component can include a ScriptManagerProxy control.For example, the ScriptManagerProxy control enables you to add scripts and services that are specific to nested components.
Exemplos de código
Walkthrough: Criando um site da Web AJAX-ativado
Demonstra Passo a passo: Globalizando uma data usando o script de cliente
Criando Scripts de Cliente Personalizado Usando a Biblioteca Microsoft AJAX
Demonstra Passo a passo: Criando e usando serviço Web habilitado para AJAX
Introdução ao Controle UpdatePanel
Introdução ao Controle UpdateProgress
Demonstra Passo a passo: Introdução ao controle Timer
Atribuindo Referências a Scripts Dinamicamente
Adicionando recursos de cliente a um controle de servidor Web
Criar Controles de Cliente Personalizados AJAX
Criando Componentes Não Visual de Cliente personalizados
Referência de Classe
Classe |
Descrição |
---|---|
A server control that makes script resources available to the browser, which includes the Microsoft AJAX Library and the functionality that enables partial-page rendering. |
|
A server control that enables nested components to add script and service references if the page already contains a ScriptManager control. |
Consulte também
Conceitos
Visão Geral do Ciclo de Vida da Página ASP.NET