|
August 28, 2002 Sending JavaScript to the Client Tips: August 2002
Yehuda Shiran, Ph.D.
|
|
You can return strings to the client browser with Response.Write(). The output of the Response.Write() statement is incorporated into the page being processed, and displayed at the client browser. Instead of just strings, we can also write scripts with Response.Write(). This script will run on the client browser. It opens the way for popping up message boxes at the client browser, using the client-side JavaScript alert() method. This is how you can pop up windows at the client side from ASP.NET pages running on the server side.The following ASP.NET page demonstrates how to do it:
We call the popup() function from within the <% %> construct. We concatenate a string ("Today is ") and a variable (today), and pass it to popup(). The popup() function uses Response.Write() to return a script. The script is as follows:
In order to avoid parsing of the < and > brackets by the server, we split </SCRIPT>, to force their concatenation only at the client side.
Here is the window that pops up at the client side, when setting the URL of the browser to
People who read this tip also read these tips: Look for similar tips by subject: |