Example learning Dreamweaver MX ASP Programming Basics 1

Source: Internet
Author: User
Tags format case statement end execution expression variables variable dreamweaver
dreamweaver| programming

Pre-read tips: To read this article, make sure you have learned to use the DW MX aspvbscript mode of "server behavior", but you do not need to understand ASP syntax.

This article if there is a wrong or technical error, please master in the forum posts to correct.

Since I posted in the Udsky Forum on the DW MX Design Forum News, netizens response eagerly, most netizens are supported. And as far as I know, many friends are only familiar with DW MX to design static pages, background procedures are not too familiar. So I first try to write this article for "rookie" before a good "tutorial" a turn. I believe that "rookie" are not fools, if willing to work hard, others can do, you can do!

Because of the server behavior template functionality limited to DW MX, it is difficult to design a complex forum with it (of course, if you're just doing a "practical forum" that's more powerful than a message). Below and everybody to discuss the basic syntax of ASP, considering our "rookie" generally not familiar with the ASP, this article is not a complete course of ASP, but for the DW MX and the beginning of the novice ASP users and write, simply introduce a few basic objects, methods, attributes and simple application examples, these in the DW MX ASP server Design for the use of very frequent; that is to say, you do not need to have the slightest understanding of the ASP, as long as you take the time to practice the small examples described in this article, remember the use of these objects, and then with the DW MX strong server behavior, design your own server application.

If you are an ASP master, this article on you have nothing to read, if there is a mistake, please enlighten! Our "rookie" friends are not, although online, books on this tutorial articles are numerous, but there are few for DW MX, and too much of the "grammar introduction", annoying and dry. Well, gossip less, turn to the point.

Several basic objects are covered in this article:

    • Request Object
    • Response Objects
    • Session Object

A discerning eye. This is the ASP built-in objects of three of them, the use of very frequent, if you want to learn ASP, these few objects must be proficient in mastering. Here are a few examples of how these objects are used, properties, and so on, every time after a knowledge point will immediately analyze the DW MX generation code function, and try to write the implementation of the DW MX some of the functions of the code, but the code than DW MX automatic generation of much simpler, as long as the main example, so that everyone has a perceptual knowledge, Easy to understand and digest.

One,request Object--Receive client data

The Chinese translation of requests is "request". Request object is the ASP "eyes" and "ear", the client's light and dark movement, it is responsible for supervision, such as form submission, url parameter transmission, etc., are one by one of its hands. Say nothing, try your skill first. Open DW MX, execute "file"--"new" command, pops up the New Document dialog box, select Dynamic page in categories on the General tab, and the dynamic page entry selects ASP VBScript, because as long as we use VBScript as the scripting language, click Create.

Syntax format for the request object:

Request[Collection | properties | methods | (variables)]

Use the Request object to access any information that is delivered based on HTTP requests, including parameters, cookies, and user authentication that are passed from the client HTML table alone Posp or Get methods.

Instance one, using the form method of the request Object

Insert form, text field and twist Press, text domain name is called "oo", form method is "POST", two other dongdong do not need to reason.

Write the following code in the <body></body> tab:

<%=request.form ("oo")%>

The complete code is as follows:

<% @LANGUAGE = "VBSCRIPT" codepage= "936"%>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<title> Untitled Document </title>

<body>
<%=request. Form ("oo")%>
<form name= "Form1" method= "Post" action= "" >
<input name= "oo" type= "text" id= "oo" >
<input type= "Submit" name= "Submission" value= "submitted" >
</form>
</body>

Among them, the text domain name must be with request. the variable names in the form ("variables") collection in form ("oo") match to receive data submitted by the client form, such as OO in this example. Try pressing the "F12" button preview, in the Text field to enter some random content, press the "Submit" button, is not the content shown just entered?

In this case, we use the Request.Form method, which is used to receive form variables, as well as "<%", "%>", "=" symbols, "<%" and "%>" are ASP's delimiters, Code that contains an ASP statement uses the delimiter to differentiate between other HTML code and the server can interpret it. "=" has the output function, without it will not be able to output data to the client, you can take this symbol to remove the test and the reaction is not the same (nothing shows).

In addition to the Request.Form method, there are request. The QueryString method, unlike Request.Form , is that it receives URL parameters, such as the format address that you see when browsing the Web:

Use of Http://localhost/asp/uio.asp?oo=request objects

In this address format, use "?" In the separate address information URL parameter, "? "Before the" http://localhost/asp/uio.asp "for address information,"? "Use of the Oo=request object" is the URL parameter, where "oo" is the variable that hosts the data, the variable name you can call, should be mainly English letters, you can include the underscore "_", but do not begin with an underscore. Next, on the QueryString method of the Request object, click the hyperlink in the page to open another page and pass the accompanying data to the page.

Instance two, using the QueryString method of the request Object

Target page: file name is bbb.asp

ASP statement:

<%=request. QueryString ("UU")%>

Complete code:

<% @LANGUAGE = "VBSCRIPT" codepage= "936"%>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<title> Untitled Document </title>

<body>
<p><%=request. QueryString ("UU")%></p>
<form name= "Form1" method= "Post" action= "" >
<input name= "oo" type= "text" id= "oo" >
<input type= "Submit" name= "Submission" value= "submitted" >
</form>
</body>

Delivery page: file name is aa.htm

<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<title> Untitled Document </title>

<body>
<a href= "bbb.asp?uu= pass me to bbb.asp page!" "> Click here to pass the data to the Bbb.asp page
</a>
</body>

Hyperlink format for <a href= "untitled-3.asp?uu= send me to bbb.asp page!" "> link text </a>

To execute the aa.htm page first, click on the hyperlink, is not the "pass me to bbb.asp page!" " passed to the target page?"

Request.Form and request. Comparison of QueryString

In addition to the reception methods, there is the problem of passing the data volume, the Request.Form method can receive no restrictions on the data, and Request.QueryString can only receive data less than 2KB data, of course, the latter is faster than the implementation of the former. General requests are used when requesting queries from the database . QueryString method, because the query is only a few keywords, there is no need to use the Request.Form method and cause the query speed slow. In addition,request.  The QueryString method also displays the data information in the client browser address bar and is less secure. The Request.Form method does not have these problems, so it is widely used in many text fields to submit data and user login.

The request object can also not specify the specific use of the QueryString or form method , such as request ("variable"), because it can be automatically recognized, but it is indicated as good, otherwise, It also takes a bit of time to make its own judgments, affecting the efficiency of program execution.

Analysis of code in DW mx

This is the statement that receives the URL parameter when inserting the Command1 command Server behavior

<%

if (Request.QueryString ("id") <> "") Then Command1__mmid = Request.QueryString ("id")

%>

The purpose of this code is to assign the "id" bearer data information to the variable when the URL parameter "id" that is received by the QueryString method of the Request object is not emptycommand1_ _mmid"(plainly, that is, command1__mmid=ID) so that the next program that needs to invoke the"command1__mmid"variable is used. Here is a if.....then judgment statement, which will be mentioned later.

Note: Related comparison operator comments:

<> is not equal, the result is true when the values of the left and right expressions are not equal. For example, 1<>2, the result is true.

= Equal, when the values of the left and right expressions are equal, the result is true. For example, to=to, the result is true.

> is greater than, when the value of the left expression is greater than the value of the right expression, the result is true for example, 5>3, the result is true.

< is less than, the result is true when the value of the left expression is less than the value of the right expression. For example, 3<5, the result is false.

>= The result is true when the value of the left expression is greater than or equal to the value of the right expression.

<= The result is true when the value of the left expression is less than or equal to the value of the right expression.

example Three, use the request object to combine conditional judgment statement

Before you learn this example, try some of the super simple things in the VBScript script, because the main part of the ASP is controlled by VBScript scripts, such as loops (known as "repeat regions" in DW MX), the use of conditional judgments to execute commands, and so on. Here will not introduce too much VBScript grammar, please rest assured, hehe!

1. Common If...then...else...end If Selection statements

If you understand English (I use Jinshan fast translation to know Ah, alas!) Who call me the English blind, you can probably see the meaning of this statement, is "if ... And then... Other... End ", yes, its role is explained by itself, that is:

if (if what) ... then (then)

Execute ASP Statement commands ...

ElseIf (the last condition is not satisfied, when to judge what when) ... then (then)

Execute ASP Statement commands ...

...................

Else (otherwise, last)

Execute ASP Statement command ....

End if (ends)

So straightforward, you should understand a little bit of it? What the??? Don't you get it? We all use examples to enhance understanding of it.

Instance three (1), new ASP file, file name: ccc.asp (whatever)

Insert forms, lists/menus, and buttons, form method "POST", press type "Submit Form", List/menu name is "BB"

Don't worry about the rest.

In the middle of the <body></body> label to the statement:

<% if Request.Form ("BB") =1 Then
Response.Write "Hello!" You are an ordinary netizen! "
ElseIf request.form ("BB") =2 Then
Response.Write "Hello!" You are a senior station friend! "
ElseIf request.form ("BB") =3 Then
Response.Write "Hello!" You're an admin! "
Else
Response.Write "I'm sorry! I don't know who you are! "
End If
%>

The complete code is:

<% @LANGUAGE = "VBSCRIPT" Codepage= "936"%>
<meta http-equiv= "Content-type" content=; charset=gb2312
<title> Untitled document </TITLE>
<body>
<% if Request.Form ("BB") =1 then
Response.Write "Hello!" You are an ordinary netizen! "
ElseIf request.form (" BB ") =2 then
Response.Write" Hello! " You are a senior station friend! "
ElseIf request.form (" BB ") =3 then
Response.Write" Hello! " You're an admin! "
Else
Response.Write" I'm sorry! I don't know who you are! "
End If
%>
<form name=" Form1 "method=" Post "action=" "
<select name=" BB "id=" BB "
<option value= "1" >1</option>
<option value= "2" >2</OPTION>
<option value= "3" >3 </option>
<option value= "0" >0</OPTION>
</select>
<input type= "Submit" Name= " Submit "value="
</form>
</body>

Press "F12" key preview, select "1", the page will output: Hello! You are an ordinary netizen!

When you select "2", the page will output: Hello! You are a senior Netizen!

When you select "3", the page will output: Hello! You're an admin!

When you select "0", the page will output: I'm sorry! I don't know who you are!

This example uses the ElseIf clause to select among multiple conditions, and you can add more than one ElseIf clause at any point.

This example uses a "Response.Write" object to output data to the client, which will be mentioned later.

You can also use If....then....else to press the output of the HTML code (hide and display)

<% if Request.Form ("BB") =1 then%>
How are you doing! You are an ordinary netizen!
<%elseif request.form ("BB") =2 then%>
How are you doing! You are a senior station friend!
<% elseif request.form ("BB") =3 then%>
How are you doing! You're an admin!
<%else%>
I'm so sorry! I don't know who you are!
<% End If%>

2.SELECT Case Structure Selection statement

The IF....THEN....ELSE structure described earlier is useful, but adding too many elseif clauses makes the code cumbersome.

The Select Case is a flexible form of the IF...THEN...ELSE structure that makes the code concise and easy to read. The following example:

Example three (2): Put the Code of instance Three (1):

<% if Request.Form ("BB") =1 Then
Response.Write "Hello!" You are an ordinary netizen! "
ElseIf request.form ("BB") =2 Then
Response.Write "Hello!" You are a senior station friend! "
ElseIf request.form ("BB") =3 Then
Response.Write "Hello!" You're an admin! "
Else
Response.Write "I'm sorry! I don't know who you are! "
End If
%>

Modified into:

<% Select Case Request.Form ("BB")
Case "1"
Response.Write "Hello!" You are an ordinary netizen! "
Case "2"
Response.Write "Hello!" You are a senior station friend! "
Case "3"
Response.Write "Hello!" You're an admin! "
Case Else
Response.Write "I'm sorry! I don't know who you are! "
End Select
%>

The execution result is exactly the same as instance three (1).

As you can see, the Select Case structure is easy to read and the Select Case structure uses only one simple test expression at its beginning, compares the result of the expression with the value of each of the occurrences, and executes the associated statement block if it matches. The Select Case structure is formatted as follows:

Select Case < variable >

Case < value 1>

ASP Program Statement 1

case< value 2>

ASP Program Statement 2

....

Case Else

ASP program Statement n

End Select

Of course, you can also use the Select Case statement to press the output of the HTML code (hide and display)

<% Select Case Request.Form ("BB")%>
<% case "1"%>
How are you doing! You are an ordinary netizen!
<% case "2"%>
How are you doing! You are a senior station friend!
<%case "3"%>
How are you doing! You're an admin!
<%case else%>
I'm so sorry! I don't know who you are!
<%end select%>

Next page



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.