Response.End () Usage _ Application techniques in ASP

Source: Internet
Author: User

ASP development may sometimes use a large segment of if ... else, but if the content of dynamic Response.Write, you want to more convenient to read the code, you can use Response.End () to the implementation of ASP, also similar to the use of break, for example:

Copy Code code as follows:

if (userid= "") or (password= "") Then
Response.Write ("<script lanuage=javascript>alert (' UserName or Password is empty! '); location.href= '. /default.asp ';</script> ')
Response.End () ' Here is the break end if the following is not NULL for reading the database operation, omitting the N line of code

This way, when the incoming username or password is empty, the automatic write prompt message information, and then Response.End () interrupts the program, thereby achieving if ... else's role.

In addition, when using Response.End, it is our daily debugging procedures, such as

Output concatenation of the SQL statement, and do not want to execute the following code, then you can do so

Copy Code code as follows:

Sql= "SELECT * from UserInfo"
Response. Write (SQL)
Response. End ()
Rs.Open sql, conn,1,1 ' This sentence is not going to be executed.

If you are afraid to join the Response.End () place too much and the official release time is not good to comment out, you can use a function to encapsulate it, such as the following code:

Copy Code code as follows:

Sub Debug ()
Response.End ()
End Sub

The code above is modified as follows:

Copy Code code as follows:

Sql= "SELECT * from UserInfo"
Response. Write (SQL)
Debug ()
Rs.Open sql, conn,1,1 ' This sentence is not going to be executed.

So when it is officially released, commenting out the statements in the function debug can play a role in debugging, but this also has the problem that if you use too many debug (), the program may not be interrupted as needed during debugging, and sometimes you don't want these places to be interrupted. So we're going to refactor the debug () function further, as follows:

Sub Debug (isbreak) ' isbreak is an argument of Boolean value and is interrupted if set to true, otherwise no interrupt processing if Isbreak then Response.End () EndEnd Sub

The code of use is as follows:

Copy Code code as follows:

Sql= "SELECT * from UserInfo"
Response. Write (SQL)
Debug (False)
Rs.Open sql, conn,1,1 ' This sentence is going to be executed rs.close ()
Sql= "SELECT * from Product"
Response.Write (SQL)
Debug (True)
Rs.Open sql,conn,1,1 ' This sentence will not be executed

Well, this basically can meet our control of the interruption of the demand, but only a simple analysis, in fact, is still very imperfect, debugging needs may still have a lot, need to meet, but also need further reconstruction. In fact, program development is a reconstruction and reconstruction of the process, or how to come out so many design patterns, are predecessors from the actual development of the reconstruction process summed up the experience, it is worthy of reference.

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.