---
title: "Registering Client Script in Asp.net"  
description: "IntroductionClient-side script generally refers to the class of computers programs on the web that are executed client side by the user’s browser, ins"  
author: "Chris Anderson"  
published: 2011-08-09  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/220/registering-client-script-in-asp-dot-net  
category: "asp.net"  
tags: ["asp.net"]  
reading_time: 2 minutes  

---

# Registering Client Script in Asp.net

##### Introduction

Client-side script generally refers to the class of computers [programs](https://www.mindstick.com/forum/157528/how-exceptions-can-be-handled-in-sql-server-programs) on the web that are executed [client side](https://www.mindstick.com/forum/160418/what-are-the-best-practices-for-securely-storing-bearer-tokens-on-the-client-side) by the user’s [browser](https://www.mindstick.com/blog/155254/which-is-the-best-internet-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](https://yourviews.mindstick.com/view/87829/how-to-improve-web-application-speed-with-lazy-loading) or when user does a submit on the form.

You have a clientscriptmanager object on each [aspx page](https://www.mindstick.com/forum/218/how-do-i-create-an-aspx-page-that-periodically-refreshes-itself). You have the object name is ClientScript; using ClientScript you can [register](https://answers.mindstick.com/qa/93542/do-we-need-to-register-or-sign-up-for-kidszone) the script in 4 modes:

1. RegisterClientScriptBlock() method add the script before the [controls](https://www.mindstick.com/articles/66/how-to-create-controls-at-run-time-in-csharp-dot-net) are rendered in the page. So the scripts we are registered can't [access](https://www.mindstick.com/articles/12994/how-foreigners-can-access-blocked-websites-in-china) 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](https://www.mindstick.com/forum/12680/call-custom-js-function-inside-jquery-ajax-that-is-defined-in-an-external-js-file) 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')");           
```

---

Original Source: https://www.mindstick.com/blog/220/registering-client-script-in-asp-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
