spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column116


JScript .NET, Part X: Displaying Information

Sr Instructional Designer D2L-Moodle,Clearance
WSI Nationwide, Inc.
US-NJ-Fort Monmouth

Justtechjobs.com Post A Job | Post A Resume
Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs


Popping Up Windows at the Client

In pages 5 and 6, we have shown how to 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:


<%@ Page LANGUAGE="JScript" SRC="col116ex7.aspx.js"
  INHERITS="COL116.codeBehind"
   AutoEventWireup="true" EnableViewState="true"%>
<HTML>
<SCRIPT LANGUAGE="JScript" runat="server">
function popup(str) {
  Response.Write("<script> alert ('" + str + "')
    </scr" + "ipt>");
}
var today : Date = new Date();
</SCRIPT>
<HEAD>
  <TITLE>Hello World Test</TITLE>
</HEAD>
<BODY STYLE="font-size:12;
    font-family:arial,verdana,sans-serif;">
  <P ALIGN="center"><% popup("Today is " + today); %></P>
  <FORM RUNAT="server">
  <P ALIGN="center"><ASP:LABEL ID="message" RUNAT="server">
  </ASP:LABEL></P>
  </FORM>
</BODY>
</HTML>

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:

<SCRIPT>
  alert(str);
</SCRIPT>

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 http://localhost/column113/col116ex7.aspx:

Notice that the Code Behind JScript .NET code, col116ex7.aspx.js, is identical to that on Pages 5 and 6.

Next: A Final Word

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint


Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: August 12, 2002
Revised: August 12, 2002

URL: http://www.webreference.com/js/column116/***PASTE FILENAME HERE***