asp.net WebForms – Top Tasks for Improving Responsiveness

Only use ViewState when necessary

ViewState is enabled by default, using it can significantly increase the amount of data rendered by your page. So it is recommended to disable it when it is not needed, especially when you use data-bound controls, all of which use view state to save their state across post backs.

Viewstate is useful, whenever a page posts back to itself. If this is not the case, it is convenient to disable the ViewState.

You can selectively disable the VIEWSTATE of the controls, DataGrids etc that you use on the page if these controls do not post back to the same page.

Set the ScriptManager LoadScriptsbeforeUI property to false.

If you are using WebForms with Microsoft Ajax, you can set the LoadScriptsBeforeUI property of the ScriptManager control to false.

This property value is true by default. In that case, the manager will render each referenced script using the ScriptManager at the top of your HTML.

If the property is set to false, the manager will render the scripts at the bottom of your HTML.

Browsers stop parsing and rendering HTML when they are downloading and executing scripts. Therefore, having the scripts at the bottom improves the perceived performance (especially if your scripts are big), because the whole HTML will be renderer first.

Combine Client Scripts into a Composite Script

Combining multiple JavaScript files into a single file (composite script), reduces the number of browser requests. The result is faster download times for the user and less load on the Web server.

ASP.NET AJAX enables you to combine multiple JavaScript files into a single composite script by using composite script references in the ScriptManager control or ScriptManagerProxy control. If scripts involve dependencies, such as scripts that call functions in other scripts, you must manage the scripts so that they are registered in the appropriate order.

The following code shows how to combine some scripts using the ScriptManager control.

HTML

<html >

<head runat=”server”>

    <title>Combining Scripts</title>

</head>

<body>

    <form id=”form1″ runat=”server”>

    <asp:ScriptManager ID=”ScriptManager1″ runat=”server”>

        <CompositeScript>

            <Scripts>

                <asp:ScriptReference Path=”~/Scripts/Script1.js” />

                <asp:ScriptReference Path=”~/Scripts/Script2.js” />

                <asp:ScriptReference Path=”~/Scripts/Script3.js” />

            </Scripts>

        </CompositeScript>

    </asp:ScriptManager>

    <h2>Combining Scripts</h2>

    <p>This example shows how to combine multiple client scripts into

    a single composite script.</p>

    <div>

        <input id=”Button1″ type=”button” value=”Button 1″ onclick=”buttonClick1()” />

        <span id=”Span1″></span><br /><br />

        <input id=”Button2″ type=”button” value=”Button 2″ onclick=”buttonClick2()” />

        <span id=”Span2″></span><br /><br />

        <input id=”Button3″ type=”button” value=”Button 3″ onclick=”buttonClick3()” />

        <span id=”Span3″></span>

    </div>

    </form>

</body>

</html>

Minimize the content of the UpdatePanel to reduce ViewState

ViewState should be used only when you need to persist changes to the state of a Web Form across postbacks.

When a postback occurs in an UpdatePanel the page’s entire ViewState is passed to the server, updated, and then the updates are passed back down to the browser. So the size of your page’s ViewState has a considerable effect on the performance of your UpdatePanel postbacks.

The recommendation is to minimize the content of the UpdatePanel: the <ContentTemplate> should only include controls that are necessary to refresh.

Note: For more information about this, see Update Panel Challenges .

 

Use UpdatePanels when using Custom Validators

If you need to perform cross-field validation in the server, consider using a CustomValidator control inside an UpdatePanel control. By placing the validator inside an UpdatePanel, you avoid full postbacks; therefore, the UI’s responsiveness improves.

Don’t use LinkButton controls, use Button controls instead

Advertisements

About msarm

Aspiring Enterprise Architect.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s