What is Script Manager?
ScriptManager control is used to provide support for client-side features AJAX. It manages the client script for AJAX enabled web page. It support partial-page rendering.
Features of script Manager
1. Handling Partial Page rendering - Script Manager manages partial page rendering of page. When a page have one or more update panel, then only the part of page that is inside the update panel is rendering. Script Manager have property EnablePartialRendering that determines whether the page participates in partial update or not.
2. Handling errors-
i) AllowCustomErrorsRedirect- This property determines how the custom error section is used in web.config when error occur in asynchronous postback.
ii) Script Manger handle AsyncPostBackError event- This event is raised when page is having error during Asynchronous postback.
iii) AsyncPostBackErrorMessage-This property is the error message which is sent to browser.
3. Registering custom scripts Script Manager controls manages the resources (scripts,styles,arrays) that participates in partial page rendering.
4. Registering web services- To register webservice that call from AJAX enabled page, we register web service by adding Script Manager control Services collection.
Examples of Script Manager
In aspx page, suppose we have bind dropdown according to another dropdown value. Then we put these 2 dropdowns in update panel . Here below is the code :
< asp:ScriptManager Id="ScriptManager1" runat="server">
< /asp:ScriptManager>
< asp:UpdatePanel ID="UserClassification" runat="server" >
< ContentTemplate>
Name
< asp:DropDownList ID="drpName" runat="server" AutoPostBack="true">
< asp:ListItem Text="Select" Value="0">
< /asp:DropDownList>
< asp:DropDownList ID="drpCategory" runat="server" >
< asp:ListItem Text="Select" Value="0">
< /asp:DropDownList>
< /ContentTemplate>
< /asp:UpdatePanel>
In code behind here below is the code:
protected void drpName_SelectedIndexChanged(object sender, EventArgs e)
{
DataTable dtCategory =new DataTable();
dtCategory = GetCategory(drpName.SelectedValue);
dtCategory.DataSource = dtCategory;
dtCategory.DataTextField = "CategoryName";
dtCategory.DataValueField = "CategoryID";
dtCategory.DataBind();
}
0 Comment(s)