JavaScript General - What are the ways to emit client-side JavaScript from server-side code in ASP.NET?
Interview Question Database For Software Developers
|
|
| 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? | | 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.
| | ID: 2119 | Rank: 301 | Votes: 0 | Views: 82 | Submitted: 20080805 |
Copyright © 2008 FYIcenter.com
All rights in the contents of this Website are reserved by the individual author.
No part of the contents may be reproduced in any form without author's permission.
|
|
|