Click here to Skip to main content
15,887,676 members
Articles / Web Development / HTML

Load and Display Page Contents Asynchronously with Full Postback Support

Rate me:
Please Sign up or sign in to vote.
4.87/5 (72 votes)
14 Sep 2010Ms-PL9 min read 587.6K   4.3K   242  
An AJAX UpdatePanel with less communication overhead and better performance
// Copyright (c) iucon GmbH. All rights reserved.
// For more information about our work, visit http://www.iucon.com

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;

namespace iucon.web.Controls
{
    class ClientScriptRegister
    {
        public void RegisterScripts(ScriptManager scriptManager, Page parentPage)
        {
            ScriptManager parentScript = ScriptManager.GetCurrent(parentPage);
            ClientScriptManager clientScript = parentPage.ClientScript;

            foreach (RegisteredScript script in scriptManager.GetRegisteredStartupScripts())
            {
                // overwrite UniqueScript-ID 
                // because it could conflict with these generated inside the PartialUpdatePanel
                string key = script.Key;
                if (key.StartsWith("UniqueScript"))
                    key = "UpdatePanel" + key;

                if (!clientScript.IsStartupScriptRegistered(script.Type, key))
                {
                    ScriptManager.RegisterStartupScript(parentPage, script.Type, key, script.Script, script.AddScriptTags);
                }
            }

            foreach (RegisteredScript script in scriptManager.GetRegisteredClientScriptBlocks())
            {
                if (script.ScriptType == RegisteredScriptType.ClientScriptInclude)
                {
                    if (!clientScript.IsClientScriptIncludeRegistered(script.Type, script.Key))
                        ScriptManager.RegisterClientScriptInclude(parentPage, script.Type, script.Key, script.Url);
                }
                else
                {
                    if (!clientScript.IsClientScriptBlockRegistered(script.Type, script.Key))
                        ScriptManager.RegisterClientScriptBlock(parentPage, script.Type, script.Key, script.Script, script.AddScriptTags);
                }
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


Written By
Software Developer (Senior) iucon GmbH
Germany Germany
My name is Stefan and I am working at iucon GmbH (http://www.iucon.de), a german software development company.
Our main focus is the development of online shops including the ERP backend.
We also develop custom software solutions for our customers and are able to support other companies and developers in using the following technologies, because we use them every day Wink | ;-)

- .NET Framework 2.0
- .NET Framework 3.0
- .NET Framework 3.5
- Windows Workflow Foundation
- C#
- ASP.NET
- ASP.NET AJAX
- SQL Server 2005 T-SQL
- ADO .NET
- Reporting Services
- Integration Services
- XML Webservices
- Database Design
- Payment systems

You can find information about our ERP software iuBIZ on http://www.iubiz.de which is totally written in .NET by using most of the cool new technologies like Workflow Foundation, Reporting Services, ClickOnce-Deployment. Feel free to take a look at the website and see Microsoft's new technologies in action Wink | ;-)

Comments and Discussions