ScriptManager Role in Ajax

The controls that UpdatePanel and ScriptManager are used for the ASP.NET AJAX Enabled sites.

  • We use them; firstly, because in traditional webpages the entire page is loaded after a postback, the HTML sent to the browser is much larger than it needs to be.
  • Second, because the entire page is replaced, the browser has to dismiss the old one and then draw the new one. This causes the page to “flicker,” which results in an unattractive user experience.

Untitled

The ScriptManager control serves as the bridge between the client page and the server. As it is like a bridge, we have to use this control if any of the other AJAX controls needs to be added. It manages script resources (the JavaScript files used at the client), takes care of partial-page updates as shown earlier, and handles interaction with web site for things like web services and the ASP.NET application services such as membership, roles, and profile. Whenever one of the controls within the UpdatePanel causes a postback to the server, only the content within that UpdatePanel is refreshed.

If we analyze the data that gets sent from the server to the browser (using a network analysis tool like Fiddler or Wireshark), we would see that only a limited amount of data gets sent to the client.

we usually place the ScriptManager control directly in a content page if we think our need Ajax capabilities on only a handful of pages.

If we are going to use Ajax functionality in many of your ASPX pages, we can place the ScriptManager in the master page, so it’s available in all pages that are based on this master.

we can only have one ScriptManager per page (i.e. only one bridge, if there happens two bridges then the page request/response may get confused from where to go!? :D), so if we add one to a master page, we can’t add another one to a content page. In order to access a ScriptManager control that is defined in a master page from a content page, we can use the ScriptManagerProxy.

ClientScriptManager–Registers the client script with the Page object.

This member is overloaded. For complete information about this member, including syntax, usage, and examples, click a name in the overload list.

ClientScriptManager.RegisterClientScriptBlock– Registers the client script with the Page object using a type, key, and script literal.

RegisterClientScriptBlock–Registers a client script block with the System.Web.UI.ScriptManager control for use with a control that is inside an System.Web.UI.UpdatePanel control, and then adds the script block to the page.

RegisterStartupScript–Registers a startup script block for a control that is inside an System.Web.UI.UpdatePanel by using the System.Web.UI.ScriptManager control, and adds the script block to the page.

RegisterAsyncPostBackControl-

Registers a control as a trigger for asynchronous postbacks.The RegisterAsyncPostBackControl method enables to register Web server controls as triggers so that they perform an asynchronous postback instead of a synchronous postback. When the ChildrenAsTriggers property of an UpdatePanel control is set to true (which is the default), postback controls inside the UpdatePanel control are automatically registered as asynchronous postback controls.

ScriptManager1.RegisterAsyncPostBackControl(WebUserControl1);---for register of usercontrol
ScriptManager1.RegisterAsyncPostBackControl(Button1);---for register of button1
protected void Button1_Click(object sender, EventArgs e)
    {
        Label1.Text = "Panel refreshed at " + DateTime.Now.ToString();
           ---button click update the updatepanel
    }

  1 comment for “ScriptManager Role in Ajax

  1. Kumar
    September 9, 2014 at 10:42 am

    The ScriptManager control manages client script for AJAX-enabled ASP.NET Web pages. So in order to use the UpdatePanel or any other AJAX controls, we must have to use the ScriptManager control at the beginning.
    Manages ASP.NET Ajax script libraries and script files, partial-page rendering, and client proxy class generation for Web and application services.
    ScriptManager is a server-side control that sits on your Web Form and enables the core of ASP.NET AJAX. Its primary role is the arbitration of all other ASP.NET AJAX controls on the Web Form and the addition of the right scripting libraries to the Web browser so that the client portion of ASP.NET AJAX can function. Often you will find yourself using the ScriptManager to register other controls, Web services, and client scripts.

Leave a Reply