Welcome to Questionaries, where you can ask questions and receive answers from other members of the community.

Let us know at info@questionaries.org

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

4 like 0 dislike
Hello guys,

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

Please give me your feedback
asked 1 year ago by rad_joshep (19,390 points)

1 Answer

2 like 0 dislike
 
Best answer
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.
answered 1 year ago by daneim (127,080 points)

Related questions