To support the display of items on a web page, Active Server Pages provides an object called Response. This object is equipped with Write() that is used to display something on a web page. To access Write(), type Response, followed by a period, followed by Write() as follows: Reponse.Write(Something); The item to display must be written in the parentheses. If you want to display an empty space, a character, or a group of characters, pass it double-quoted in the parentheses of this method. Here is an example: <%@ Page Language="C#" %> <html> <head> <title>Grier Summer Camp</title> </head> <body> <center><h1>Grier Summer Camp</h1></center> <% Response.Write("Coolfront Island"); %> <p>Coolfront Island, our star house of the season, is a 2-story like chateau featuring nicely finished brown bricks whose sight is tremendously appealing. The estate introduces two large living rooms with exquisite velour furniture. The colonial veranda offers a patio spanning two walls with a lost view down the far-reaching landscape. In this particular setting, besides their usual activities, children will learn special human needs to make their experience unforgettable.</p> <p>Please consult our catalogue and see why the Washington Tribune called us <i>the most attractive summer camp of the area</i>.</p> <% Response.Write("Grier Summer Camp"); %> </body> </html> This would produce:
If the item to display is a regular number, whether natural or decimal, you can write it without the quotes in the parentheses of Response.Write(). Here is an example: <%@ Page Language="C#" %> <html> <head> <title>Grier Summer Camp</title> </head> <body> <center><h1>Grier Summer Camp</h1></center> <% Response.Write("Coolfront Island"); %> <p>Coolfront Island, our star house of the season, is a 2-story like chateau featuring nicely finished brown bricks whose sight is tremendously appealing. The estate introduces two large living rooms with exquisite velour furniture. The colonial veranda offers a patio spanning two walls with a lost view down the far-reaching landscape. In this particular setting, besides their usual activities, children will learn special human needs to make their experience unforgettable.</p> <p>Please consult our catalogue and see why the Washington Tribune called us <i>the most attractive summer camp of the area</i>.</p> <% Response.Write("Copyright, "); %> <% Response.Write(2007); %> <% Response.Write(" Grier Summer Camp") %> </body> </html> This would produce:
When you write HTML tags in your code, the browser would interpret them and publish a result to the user. As opposed to HTML tags, most of the scripts you write are not directly intended for your user's browser. They are presented to the web server that analyzes the script and responds to it. In fact, if you include Active Server Pages scripts in <% and %>, when the resulting page is presented to the user, the script sections are removed. This also means that a curious visitor would not know what your code looks like. For example, here is the code presented to the browser from the above web page: <%@ Page Language="C#" %> <html> <head> <title>Grier Summer Camp</title> </head> <body> <center><h1>Grier Summer Camp</h1></center> Coolfront Island <p>Coolfront Island, our star house of the season, is a 2-story like chateau featuring nicely finished brown bricks whose sight is tremendously appealing. The estate introduces two large living rooms with exquisite velour furniture. The colonial veranda offers a patio spanning two walls with a lost view down the far-reaching landscape. In this particular setting, besides their usual activities, children will learn special human needs to make their experience unforgettable.</p> <p>Please consult our catalogue and see why the Washington Tribune called us <i>the most attractive summer camp of the area</i>.</p> Copyright, 2007 Grier Summer Camp </body> </html> Notice that the Response.Write(" and "); have been removed. When a file with active code is sent to the server, the server checks the <% %> sections and their contents. Any section that contains, for example, double-quoted strings passed to the Response.Write() method, is considered "as is". The server would remove <%, the Response.Write(); expression, its double-quotes, and %>. This means that, whatever you enter in the parentheses of Response.Write(); would be sent to the browser the same way you wrote it. This allows you to include HTML tags in the parentheses of Response.Write(); but it is your responsibility to send it as regular HTML code. If you make mistakes, they would be presented to the browser, the server might not care and the server cannot or would not fix it. Based on this, you can include normal HTML code between double-quotes in the parentheses of Response.Write();. Consider the following example: <%@ Page Language="C#" %> <html> <head> <title>Grier Summer Camp</title> </head> <body> <% Response.Write("<center><h1>Grier Summer Camp</h1></center>"); %> <% Response.Write("<h2>Coolfront Island</h2>"); %> <p>Coolfront Island, our star house of the season, is a 2-story like chateau featuring nicely finished brown bricks whose sight is tremendously appealing. The estate introduces two large living rooms with exquisite velour furniture. The colonial veranda offers a patio spanning two walls with a lost view down the far-reaching landscape. In this particular setting, besides their usual activities, children will learn special human needs to make their experience unforgettable.</p> <% Response.Write("<center>Copyright © 2007 Grier Summer Camp<center>"); %> </body> </html> When the server receives this code, it removes the <% Reponse.Write(" and the "); %> sections. Then its sends the rest to the browser: <%@ Page Language="C#" %> <html> <head> <title>Grier Summer Camp</title> </head> <body> <center><h1>Grier Summer Camp</h1></center> <h2>Coolfront Island</h2> <p>Coolfront Island, our star house of the season, is a 2-story like chateau featuring nicely finished brown bricks whose sight is tremendously appealing. The estate introduces two large living rooms with exquisite velour furniture. The colonial veranda offers a patio spanning two walls with a lost view down the far-reaching landscape. In this particular setting, besides their usual activities, children will learn special human needs to make their experience unforgettable.</p> <center>Copyright © 2007 Grier Summer Camp<center> </body> </html> The browser then receives normal HTML tags that it must interpret and present the result in the intended web page:
In the same way, you can write any sophisticated HTML code in the parentheses Reponse.Write();. This consequently means that if you pass bad HTML code to a Response.Write() method, the result may be unpredictable.
Although you can do many things using HTML, CSS, and C#, every language has its own shortcomings. To complement them, you combine them with additional languages. As an example, you can use or insert JavaScript to your ASP.NET code. There are certainly various rules you must follow but you should know that it is available.
One of the objects you can borrow from JavaScript is its message box, which you can display in response to a user clicking something on a web page. To support message boxes, the JavaScript language provides the alert() function. To call this function in your ASP.NET code, you must qualify it from JavaScript. The syntax of the alert() function is: javascript:alert(Message); This function takes one argument, passed as a string. To call it, you can create it as part of a hyperlink. Here is an example: <a href="javascript:alert('Your time sheet has been received');">Submit</a> When the alert() function is called, it displays a a rectangular window with a message, an icon, and an OK button: In JavaScript, the alert() function is a member of the window object. Based on this, to call the function, you can qualify it from that object. Here is an example: <a href="javascript:window:alert('Your time sheet has been received');">Good</a>
|
|
|||||||||||
|