---
title: "What are the ways to emit client-side JavaScript from server-side code in ASP. NET?"  
description: "What are the ways to emit client-side JavaScript from server-side code in ASP. NET?"  
author: "Amit Singh"  
published: 2011-03-18  
updated: 2020-09-18  
canonical: https://www.mindstick.com/interview/521/what-are-the-ways-to-emit-client-side-javascript-from-server-side-code-in-asp-net  
category: "javascript"  
tags: ["javascript"]  
reading_time: 1 minute  

---

# What are the ways to emit client-side JavaScript from server-side code in ASP. NET?

The Page object in ASP. NET has two methods that allow emitting of client-side JavaScript:\
RegisterClientScriptBlock and RegisterStartupScript.\
\
Example usage:\
Page.RegisterClientScriptBlock("ScriptKey", "<script language=javascript>" + "function TestFn() { alert('Clients-side JavaScript'); }</script>");\
Page.RegisterStartupScript("ScriptKey", "<script language=javascript>" + "function TestFn() { alert('Clients-side JavaScript'); }</script>");\
\
ScriptKey is used to suppress the same JavaScript from being emitted more than once. Multiple calls to RegisterClientScriptBlock or RegisterStartupScript with the same value of ScriptKey emit the script only once, on the first call.

## Answers

### Answer by Amit Singh

The Page object in ASP. NET has two methods that allow emitting of client-side JavaScript:\
RegisterClientScriptBlock and RegisterStartupScript.\
\
Example usage:\
Page.RegisterClientScriptBlock("ScriptKey", "<script language=javascript>" + "function TestFn() { alert('Clients-side JavaScript'); }</script>");\
Page.RegisterStartupScript("ScriptKey", "<script language=javascript>" + "function TestFn() { alert('Clients-side JavaScript'); }</script>");\
\
ScriptKey is used to suppress the same JavaScript from being emitted more than once. Multiple calls to RegisterClientScriptBlock or RegisterStartupScript with the same value of ScriptKey emit the script only once, on the first call.


---

Original Source: https://www.mindstick.com/interview/521/what-are-the-ways-to-emit-client-side-javascript-from-server-side-code-in-asp-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
