Home / DeveloperSection / Blogs / Registering Client Script in

Registering Client Script in

Chris Anderson 13059 09-Aug-2011

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.


          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.

                Page.ClientScript.RegisterStartupScript (this.GetType (),        'RegisterStartupScript','alert('StartupScriptRegistered'), true);

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

    Page.ClientScript.RegisterClientScriptInclude(this.GetType(),'jQuery', '/scripts/jquery.js');


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

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

Updated 18-Sep-2014
hi I am software developer at mindstick software pvt. ltd.

Leave Comment

Please enter subject.
Please enter comments message.


Liked By