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


Using Response.Write()

Another way to display text from an ASP.NET page is by using the JScript .NET Response.Write() method. You can enclose Response.Write() within a <% %> block like this:

<% Response.Write("Hello World!") %>

You can also include it in a function definition and call the function inside a <% %> block. In ASP.NET pages, functions and variables should be defined within <SCRIPT> blocks, while executable code must be enclosed within <% %> blocks. This is very different from the way you code JavaScript on the client side. Client-side JavaScript allows placing of executable code anywhere inside <SCRIPT> blocks.

The following ASP.NET page demonstrates the usage of Response.Write():


<%@ Page LANGUAGE="JScript" SRC="col116ex6.aspx.js"
  INHERITS="COL116.codeBehind"
  AutoEventWireup="true" EnableViewState="true"%>
<HTML>
<SCRIPT LANGUAGE="JScript" runat="server">
function output(str) {
  Response.Write(str);
}
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">Today's date is  <% output(today); %></P>
  <FORM RUNAT="server">
  <P ALIGN="center"><ASP:LABEL ID="message" RUNAT="server">
  </ASP:LABEL></P>
  </FORM>
</BODY>
</HTML>

The JScript .NET code defines the variable today which is initialized to today's date and time. We also define the function output() which displays its argument with Response.Write(). Within the ASP.NET code, we call output() with the today variable as its argument:

<% output(today); %>

The Code Behind JScript .NET code, col116ex6.aspx.js, is identical to the one on Page 5, col115ex5.aspx.js.

The following window shows the outcome of setting the URL of your browser to http://localhost/column113/col116ex6.aspx:


Next: How to pop up windows at the client-side browser

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/6.html