In ASP, check for pages without data submission

Source: Internet
Author: User
Data | page

Users often encounter annoying information when they visit the site, such as they often go to the next page without actually submitting the data to the form, or they often reach a page, which is transferred in the form of a query string, such as id=236454.

If the page doesn't get information, a big error can occur. This often occurs when the page looks for an ID or some other information, and the user is connected to the page using a bookmark or search engine. Therefore, the information required by the page is lost and the page ends.

You can check to see if any data has been submitted to control this situation, then display specific error messages depending on the situation, or perform other actions, such as redirecting to the desired page.

In the following 3 examples, only one message is displayed on the screen.

Place this code directly under the <% @ language= "VBSCRIPT"%>.

For a single form, use the Post method

<%
If Request.Form = "" Then
Response.Write ("< p align=" "Center" >< font face= "Arial" ">there was
error.< br > "& vbCrLf)
Response.Write ("No Data was posted.</font >
"& VbCrLf)
Response.End
End If
% >

for a form, use the put and get methods. This also applies to pages that are connected from a query string, such as? id=236454

<%
If request.querystring = "" Then
Response.Write ("< p align=" "Center" >< font face= "Arial" ">there was
error.< br > "& vbCrLf)
Response.Write ("No Data was posted.</font >
"& VbCrLf)
Response.End
End If
% >

To include the above example, do the following work. Although there are simple methods, this example will be a good way to learn basic principles for beginners.

<%
Isdata = 0
If Request.Form < > "" Then isdata = isdata + 1
If Request.QueryString < > "" Then isdata = isdata + 1

If isdata = 0 Then
Response.Write ("< p align=" "Center" >< font face= "Arial" ">there was a error.< br >" & vbCrLf)
Response.Write ("No Data was posted.</font >
"& VbCrLf)
Response.End
End If
% >

Or

<%
Isdata = "No"
If Request.Form < > "" Then isdata = "Yes"
If Request.QueryString < > "" Then isdata = "Yes"

If isdata = "No" Then
Response.Write ("< p align=" "Center" >< font face= "Arial" ">there was a error.< br >" & vbCrLf)
Response.Write ("No Data was posted.</font >
"& VbCrLf)
Response.End
End If
%>



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.