Forum : What are the ways to emit client-side JavaScript from server-side code in ASP.NET?
Brief description  about Online courses   join in Online courses
View prabeen  patra 's Profile

What are the ways to emit client-side JavaScript from server-side code in ASP.NET?

What are the ways to emit client-side JavaScript from server-side code in ASP.NET??
Asked by prabeen patra | Mar 22, 2010 |  Reply now
Replies (1)
View teacher siliconindia 's Profile
Hi Prabeen,
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.
Mar 22, 2010