Home | Advertising Info53 USERS CURRENTLY ONLINE   
PowerASP
   Site Search Contact Us Thursday, March 13, 2025  


Checking Pages For No Data Posted




Users of you site sometimes get a nasty error message when they somehow manage to get to the page a form posts to without actually posting to the form or sometimes just a page that is linked to from another page with querystring info like so. ?ID=236454

If the page doesn't get that info it causes a big error to show up which makes things look bad.

This problem usually happens when a page is looking for an ID or some other info and the user used a bookmark or search engine link to get to the page. Then the info the page needs is missing and this ends up causing the SQL statement or something else to fail giving an error message.

You can control the situation by checking to see if any data was posted and then show a custom error message or perform some other action like redirecting them to the page you want them to be at.

In the following 3 examples a message is simply shown on the screen.

Put this code directly under the
<%@ LANGUAGE="VBSCRIPT" %>

For a form using the POST Method

<%
If Request.Form = "" Then
Response.Write("<p align=""center""><font face=""Arial"">There Was An Error.<br>" & vbCrLf)
Response.Write("No Data Was Posted.</font></p>" & vbCrLf)
Response.End
End If
%>

For a form using the PUT or GET Method.
This also works for a page that just gets Querystring info from a link.
ex:)
?ID=236454


<%
If Request.Querystring = "" Then
  Response.Write("<p align=""center""><font face=""Arial"">There Was An Error.<br>" & vbCrLf)
  Response.Write("No Data Was Posted.</font></p>" & vbCrLf)
  Response.End
End If
%>

To cover any of the situations above the examples below should work . There are shorter ways to do this.

<%
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 An Error.<br>" & vbCrLf)
     Response.Write("No Data Was Posted.</font></p>" & vbCrLf)
     Response.End
    End If
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 An Error.<br>" & vbCrLf)
     Response.Write("No Data Was Posted.</font></p>" & vbCrLf)
     Response.End
    End If
End If
%>



Article Update: 2/2/2002

Those this is still an interesting article the truth is you should really be checking for variables that you expect a a page to be receiving variables individually and deal with the situation accordingly.



   Active Server Pages Rule The World
Contact Us  
All artwork, design & content contained in this site are Copyright © 1998 - 2025 PowerASP.com and Christopher J. Williams
Banner ads ,other site logos, etc are copyright of their respective companies.
STATS Unless otherwise noted - All Rights Reserved.

Active Server Pages ASP control controls class classes module script Scripts applet CJWSoft ASPProtect ASPBanner ASPClassifieds www.aspclassifieds.com, www.powerasp.com,www.cjwsoft.com,www.aspphotogallery.com,www.codewanker.com,www.aspprotect.com,www.aspbanner.com