in JavaScript by
What Are The Ways To Emit Client-side Javascript From Server-side Code In Asp.net?

1 Answer

0 votes
by

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.

Related questions

0 votes
asked Jun 5 in Angular by Robindeniel
0 votes
asked Mar 9 in Secure Programming Practices by sharadyadav1986
0 votes
asked May 23, 2020 in Dot Net by Robindeniel
...