Dec 4, 2019 in JavaScript
Q: What Are The Ways To Emit Client-side Javascript From Server-side Code In

1 Answer

Dec 4, 2019

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.

Click here to read more about JavaScript
Click here to read more about Insurance

Related questions

Oct 16, 2019 in Design Patterns
May 14, 2019 in Other
Aug 12, 2019 in Service Discovery