Mixing HTML and Script commands

Domain Hosting image
Web Hosting
Dedicated server
ssl certificate
Web Design image
Email

You can include within ASP delimiters any statement, expression, procedure, or operator that is valid for your primary scripting language. A statement, in VBScript and other scripting languages, is a syntactically complete unit that expresses one kind of action, declaration, or definition. The conditional If .... Then .... Else statement that appears below is a common VBScript statement. <%
If Time > = #12:00:00 AM# And Time < #12:00:00 PM# Then
Greeting = "Good Morning!"
Else
Greeting = "Hello"
End If
%>

<%= Greeting%>

This statement stores either the value "Good Morning" or the value "Hello!"

in the variable greeting. The < % = Greeting% > command sends the current value of the variable to the browser.

Thus, a user viewing this script before 12:00 noon (in the Web server's time Zone) would see this line of text.

Good Morning!

A user viewing the script at or after 12:00 noon would see this line of text:

Hello!

You can include HTML text between the sections of the statement. For example, the following script, which mixes HTML within an If ... Then ... Else statement, produces the same result as the script in the previous example:

< % If time> = #12:00:00 AM# And time < #12:00:00 PM # Then % > Good Morning!
< %Else % > Hello!
< % End If %>

If the condition is true that is, if the time is midnight of after, and before noon then the Web Server sends the HTML that follows the condition ("Good Morning") to the browser, otherwise, it sends the HTML that follows Else ("Hello") to the browser. This way of mixing HTML and script commands ins convenient for wrapping the If...Then .... Else statement around several lines of HTML text. The previous example is more useful if you want to display a greeting in several places on your Web Page. You can set the value of the variable one and then display it repeatedly.

Rather than interspersing HTML text with script commands, you can return HTML text to the browser from within a script command. To return text to
the browser, use the ASP built in object Response. The following example produces the same result as the previous scripts.
<%
If Time > = # 12:00:00 AM # And Time < #12:00:00 PM # Then
Response Write "'Good Morning!"
Else
Response. Write "Hello!"
End If
%>
Response. Write sends the text that follows if to the browser. Use Response. Write from within a statement when you want to dynamically construct the text returned to the browser. For example, you might want to build a string, that contains, the values of several variables. You will learn more about the' Response object, and objects in general, in using Components and objects and sending Content to the Browser. For now, simply note that you have several ways to insert Script commands into an HTML page.

You can include procedures written in your default primary Scripting language within ASP delimiters.

If you are working with Jscripts commands, you can insert the curly braces that indicate a block of statements directly into your ASP commands even if they are interspersed with HTML tags and text. For example:

M % if (Screen resolution = = "low") {%>
This is the text version of a page
< % ) else {% >
This is the multimedia version of a page
<%}%>



Domain Name Search

www.


Copyright (C) 2007. Web Domain design hosting. All rights reserved.