Wrox Programmer Forums
|
ASP Forms As of Oct 5, 2005, this forum is now locked. Please use "Classic ASP beginner" at http://p2p.wrox.com/forum.asp?FORUM_ID=54 or "Classic ASP Professional" http://p2p.wrox.com/forum.asp?FORUM_ID=56 instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP Forms section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 8th, 2003, 02:31 PM
Authorized User
 
Join Date: Aug 2003
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default Maintaining state on a form

Hi There

How do I maintain a state for a set of variables on a self submitting form

So as the form loads the values are captured, subsequent submission of this form updates these values which are in turn captured ??, thereby allowing a user to edit a record many times but without losing any values.

This is probably really simple but I'm feeling particularly dense at the moment so any help would be appreciated.

 
Old October 8th, 2003, 03:32 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

On post back, simply retrieve the values from the Form, store them in variables and display them again. Below you'll find a simple example:

Code:
<%
  Dim FirstName
  Dim LastName
  FirstName = Request.Form("txtFirstName")
  LastName = Request.Form("txtLastName")
  ' At this point, when the page first loads
  ' both variables will be empty
  ' However, when the form has been submitted
  ' these two variables will be filled with the values
  ' from their accompanying form fields
%>
...
<form name="frmUser" action="SelfSubmittingPage.asp" method="post">
  <input type="text" name="txtFirstName" value="<%=FirstName%>">
  <input type="text" name="txtLastName" value="<%=LastName%>">
  <input type="submit" name="btnUpdate" value="Update">
</form>
No matter how many times the user presses the Update button, the form fields will keep their values.

You'll need to code the difference between the Update, and let's say, a Save button. Update just shows the new values, while the Save button actually does something with those values. You can code something like this for that:
Code:
<%
  If Request.Form("btnUpdate") <> "" Then
    ' Update button pressed. Do something and
    ' display form again
  End If
  If Request.Form("btnSave") <> "" Then
    ' Save button pressed. Do something more useful,
    ' like saving the values to a database and redirect
  End If
%>
Hope this helps,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old October 9th, 2003, 03:08 AM
Authorized User
 
Join Date: Aug 2003
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Many thanks for your reply it looks to be just what I require






Similar Threads
Thread Thread Starter Forum Replies Last Post
Maintaining state in a TreeView Nick710 ASP.NET 2.0 Professional 3 December 23rd, 2005 01:58 PM
maintaining session state in C# grs General .NET 0 January 13th, 2005 03:46 AM
Maintaining State in Tables MikeSchnell ASP.NET 1.0 and 1.1 Basics 1 March 25th, 2004 01:22 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.