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

Leave a Reply