Home > DeveloperSection > Blogs > Registering Client script in asp.net

Registering Client script in asp.net

Posted by  Chris Anderson
on    August-09-2011 3:35 AM

ASP.Net ASP.Net 
Ratings:
0 Comment(s)
 5942  View(s)
Rate this:

Registering Client script in asp.net

Introduction

Client-side script generally refers to the class of computers programs on the web that are executed client side by the user’s browser, instead of the server-side (on the web -server).

Registering Client script from server useful when, you want certain java script to be executed when page finished loading or when user does a submit on the form.

You have a clientscriptmanager object on each aspx page. You have the object name is ClientScript; using ClientScript you can register the script in 4 modes:

1.     RegisterClientScriptBlock() method add the script before the controls are rendered in the page. So the scripts we are registered can't access the controls inside the page.

Example:                             Page.ClientScript.RegisterClientScriptBlock (this.GetType (),

    "RegisterClientScriptBlockMethod"
     "alert ('ScriptBlockRegistered”,      
      true
);

 

2.    RegisterStartupScript() method add the script before the end of body tag after all the controls are rendered in the browser. So the registered script can access the controls inside the page.

Example:                                    Page.ClientScript.RegisterStartupScript (this.GetType (),

        "RegisterStartupScript",

"alert('StartupScriptRegistered'),

 true);

3.    RegisterClientScriptInclude() method refer to an external .js file that includes various script behavior.

Example:                                        Page.ClientScript.RegisterClientScriptInclude(this.GetType(),
                                                                                          "jQuery",
                                                                             "/scripts/jquery.js");

 

4.    RegisterOnSubmitStatement() method registered the script on onSubmit event of a page.

Example:                             Page.ClientScript.RegisterOnSubmitStatement(typeof(string),                                                                                               "onSubmit",  
                                                    "return alert('OnSubmit Registered')");

           


Recent Activities

Tarun Kumar added new Blog iOS Concept : Delegate   9 hours ago

Felix Pickles Created New Discussion In java, how to concatenate two arrays   15 hours ago


Tarun Kumar added new Article iOS Software Development Tools   yesterday

Don't want to miss updates? Please click the below button!