Four Ways to Locally Update a Web Page
page 4 of 12
by Xianzhong Zhu
Feedback
Average Rating: 
Views (Total / Last 10 Days): 50317/ 95

The JavaScript Way

As early as ASP.NET 1.0, several means, such as Page.RegisterClientScriptBlock and Page.RegisterStartupScript, were created to boost up the server controls with the capacities of client side. In the current ASP.NET 2.0, the above two methods both became obsolete and were replaced by class ClientScriptManager which can be accessed using Page.ClientScript.  One of the important methods of Page.ClientScript is RegisterClientScriptBlock through which we can achieve the goal of injecting client-side JavaScript blocks into object Page. Therefore, we can succeed in populating the required data from the server side, and thus ensure to locally update a web page.

About Method RegisterClientScriptBlock

There are two signatures for this method, as illustrated in the following Listing.

Listing 5

ClientScriptManager.RegisterClientScriptBlock (Type type, String key, 
    String script);
ClientScriptManager.RegisterClientScriptBlock (Type type, String key, 
    String script, Boolean addScriptTags);

A client script is uniquely identified by its key and its type. Scripts with the same key and type are considered duplicates. Only one script with a given type and key pair can be registered with the page. Attempting to register a script that is already registered does not create a duplicate of the script.

Call the IsClientScriptBlockRegistered method to determine whether a client script with a given key and type pair is already registered and avoid unnecessarily attempting to add the script.

In this overload of the RegisterClientScriptBlock method, you must make sure that the script provided in the script parameter is wrapped in a <script> element block.

The RegisterClientScriptBlock method adds a script block to the top of the rendered page. The script blocks are not guaranteed to be output in the order they are registered. If the order of the script blocks is important, use a StringBuilder object to gather the scripts together in a single string, and then register them all in a single client script block.

In this article we are not going to dig further into the related theory behind but concentrate on constructing an associated example to show the usage of method Page.ClientScript.RegisterClientScriptBlock.

Author's Note: In ASP.NET AJAX there is also a method RegisterClientScriptBlock which is provided by ASP.NET Server controlScriptManager. We can use it to create the Server side Extender for ASP.NET AJAX.


View Entire Article

User Comments

Title: d   
Name: d
Date: 2012-10-24 12:04:07 PM
Comment:
d
Title: Locally update a web page   
Name: Santosh
Date: 2010-05-04 3:41:59 AM
Comment:
It's an amazing and really very very helpful article. After reading this article, I have become a fan of this site.... I request you to not delete this article, as it may be very helpful to many people.
Title: updating a web page   
Name: Mrs.
Date: 2009-05-19 3:23:22 PM
Comment:
this is great
Title: Download Links Does Not Work   
Name: Tarik
Date: 2008-11-07 9:04:04 AM
Comment:
Good Article , But Please Review The Downloads Links
Title: Mr.   
Name: Joydip Kanjilal
Date: 2008-10-16 10:25:58 AM
Comment:
Excellent!
Title: how up date webpage   
Name: MUHAMMAD YOUNUS TOOR
Date: 2008-09-08 10:32:32 PM
Comment:
I WANT LEARN ABOUT WEB PAGE MAKIN G






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-03-29 5:50:36 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search