NCS Logo - Click for home page Northstar Developer Center
Platforms
All Platforms
.NET Framework (1.x - 4.x)
Active Server Pages
ASP.NET
C#
SQL Server
VB.NET
Visual Basic

Keywords
.NET Data Types
.NET E-mail
.NET Events
.NET Functions
.NET Object Programming
.NET System.Configuration
.NET System.Diagnostics
.NET System.IO
.NET System.Net
.NET System.Net.Sockets
Active Data Objects
ASP Architecture
ASP Black Belt
ASP Built-in Functions
ASP Built-in Objects
ASP Debugging
ASP Performance
ASP Security
ASP Syntax
ASP.NET Authentication
ASP.NET Controls
ASP.NET Data Access
ASP.NET Features
ASP.NET Master Pages
ASP.NET Page Events
ASP.NET Security
ASP.NET ViewState
Atom
Certifications
COM, DCOM, COM+
Data Access
E-Mail
Errors
Exporting Data
HTML Tips
IIS
Object-Oriented Programming
RSS
SQL
Uncategorized ASP Tips
VB API Programming
VB Forms
VB Syntax
XML

Book Support
Visual Basic 6 Bible
ASP Bible
ASP Weekend Crash Course
ASP.NET At Work
Creating Web Services

Remembering a User's Input

Written by Eric Smith, Northstar Computer Systems LLC

In many large forms, there are many possibilities for errors on the user's part. One thing that absolutely drives me nuts is to have filled out a huge form, receive an error, and have to re-enter all the data. For this reason, I don’t subject my users to the same problem. When I validate data, I will do it within the same ASP page, which means I can call the routine to show the form again. When I do this, I show all the input data as values within the form. Here's a one input box example:
<%
Call Main

Sub Main()
   If Request("action") = "validate" Then
      ValidateData
   Else
      ShowForm ""
   End If
End Sub

Sub ShowForm(strError)
   If strError <> "" Then
      Response.Write "<font color=#FF0000" & strError & "</font>
" & vbCrLf End If Response.Write "&lt;form action=""" & Request.ServerVariables("SCRIPT_NAME") _ & "?action=validate""&gt;" & vbCrLf Response.Write "&lt;input type=text name=txtInput value=""" & Request("txtInput") & """&gt;" & vbCrLf Response.Write "&lt;input type=submit name=cmdSubmit value=""Submit""&gt;" & vbCrLf End Sub Sub ValidateData() If Len(Request("txtInput")) < 5 Then ShowForm "ERROR: Data must be at least 5 characters." Response.End Else Response.Redirect "nextpage.asp" End If End Sub %&gt;
In this case, whatever the user put in the form will be redisplayed the second time the form is shown. This is a trivial example, but you can apply it to any size of form.

Keywords: [ Uncategorized ASP Tips ]

Publication Date: 7/14/2000