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.
Join MindStick Community
You need to log in or register to vote on answers or questions.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
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.