Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 12th, 2006, 02:56 PM
Registered User
 
Join Date: Apr 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Variables losing their values

I am trying to create an aspx page that shows multiple forms to the user. To do that, I have a pagenumber variable that I increment. Then I use If Then lines to display the appropriate user input pages.

The problem that I am running into is that each time a user clicks on the Next button to show the next page, I lose values from variables that stored previous page inputs. Below is an example of my coding scheme. By the time it loads the PageNumber=3 info, the UserName variable has lost its value. How do I keep the values applied to the variables?

<%@ Page Language="VB" Debug="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.IO" %>
<Script runat="server">

Public PageNumber as Integer=1
Public UserName, Phone as String

Sub Page1Next(Sender As Object, e As EventArgs)
    UserName=txtName.Text
    PageNumber=2
End Sub

Sub Page2Next(Sender As Object, e As EventArgs)
    Phone=txtPhone.Text
    PageNumber=3
End Sub
</Script>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Test</title>
</head>
<body>

<form method="POST" runat="server">

<% if PageNumber=1 then %>
Enter Name <asp:TextBox ID="txtName" Runat="server" />
<asp:Button id="btnNext1" Text="Next" Runat="server" OnClick="Page1Next" />
<% end if %>

<% if PageNumber=2 then %>
Enter Phone Number <asp:TextBox ID="txtPhone" Runat="server" />
<asp:Button id="btnNext2" Text="Next" Runat="server" OnClick="Page2Next" />
<% end if %>

<% if PageNumber=3 then %>
Enter City <asp:TextBox ID="txtCity" Runat="server" />
<% end if %>

</form>
</body>
</html>

  #2 (permalink)  
Old April 12th, 2006, 10:44 PM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

to persist values from page to page you need to use session variables, cookies or a query string. Also, some of the code you have is classic asp coding

  #3 (permalink)  
Old April 13th, 2006, 08:44 AM
Registered User
 
Join Date: Apr 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I will look into setting up session variables. Thanks for the suggestion. As you can probably tell, I'm picking up ASP.NET as I go along, so I'm sure I'm not coding in a standardized way.

  #4 (permalink)  
Old April 13th, 2006, 01:09 PM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

I know it's hard loosing old habits. Remember, any logic should be put in the code behind or a class etc. Embedded logic is the way of the past, and will just cause problems. There are several advantages to having a code behind file.

 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
losing the leading zero in binary values giles BOOK: Beginning Java 2, JDK 5 Edition 2 September 22nd, 2005 11:41 AM
Losing variables bluemat XSLT 2 October 16th, 2004 01:59 AM
Losing form variables (from posting) BunaZiua Dreamweaver (all versions) 1 February 23rd, 2004 04:46 PM
Losing session variables Justine Classic ASP Professional 3 January 16th, 2004 10:10 AM



All times are GMT -4. The time now is 04:44 PM.


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