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

Registering Client script in asp.net

Posted by  Rohit Kesharwani
on    August-09-2011 3:35 AM

ASP.Net ASP.Net 
Ratings:
0 Comment(s)
 5120  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


Kamlakar Singh added new Blog Convert Text Document to PDF File   11 days ago

Kamlakar Singh added new Article Introduction to Backbone.js   11 days ago

Kamlakar Singh added new Question Explain the AdRotator Control.   11 days ago

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