Go Back   Access World Forums > Apps and Windows > Web Design and Development > ASP and ASP.NET

 
Reply
 
Thread Tools Rating: Thread Rating: 3 votes, 5.00 average. Display Modes
Old 12-08-2005, 03:01 AM   #1
The Stoat
The Grim Squeaker
 
The Stoat's Avatar
 
Join Date: May 2004
Posts: 239
Thanks: 0
Thanked 1 Time in 1 Post
The Stoat is on a distinguished road
Persisting variable values in a webform?

Hi

I'm just starting to design some basic pages with Visual Studio .net
I've created a web application project and a form which connects to a db and displays some data. I was wondering if the forms allow persistant variables i.e. If i add a variable "above" the code is it able to persist it's value after a button has been clicked on the form like VB or is it like a webpage that would require the variable to be stored in cookie or server-variable and retrieved after submitting the form? If it's the later any idea how?

Thanks TS

Code:
Public Class NavigateData
  Dim Inc As Integer
Web Form Designer Generated Code

    Private Sub BtnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnNext.Click

        Inc = Inc + 1
        LBL_REPORT.Text = Inc

    End Sub

__________________
το χιούμορ είναι εκπαιδευμένη αυθάδεια -Αριστοτέλης

They that approve a private opinion, call it opinion; but they that dislike it, heresy; and yet heresy signifies no more than private opinion, - Thomas Hobbes
The Stoat is offline   Reply With Quote
Old 12-08-2005, 05:18 AM   #2
Kodo
"The Shoe"
 
Kodo's Avatar
 
Join Date: Jan 2004
Location: Syracuse NY
Posts: 707
Thanks: 0
Thanked 1 Time in 1 Post
Kodo is on a distinguished road
Send a message via MSN to Kodo
Quote:
Originally Posted by The Stoat
Hi

I'm just starting to design some basic pages with Visual Studio .net
I've created a web application project and a form which connects to a db and displays some data. I was wondering if the forms allow persistant variables i.e. If i add a variable "above" the code is it able to persist it's value after a button has been clicked on the form like VB or is it like a webpage that would require the variable to be stored in cookie or server-variable and retrieved after submitting the form? If it's the later any idea how?

Thanks TS

Code:
Public Class NavigateData
  Dim Inc As Integer
Web Form Designer Generated Code

    Private Sub BtnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnNext.Click

        Inc = Inc + 1
        LBL_REPORT.Text = Inc

    End Sub
if you do that then the value of one will remain in the controls viewstate each time because when you post back to the page, the value is reset to its' base of 0. So it won't increment. What you need to do is put the value in viewstate so that you can return it later if the initial value is 0.

So you would something like this to persist the value.


Code:
Public Property inc() As Integer
        Get
            Return ViewState("inc")
        End Get
        Set(ByVal value As Integer)
            ViewState("inc") = value
        End Set
    End Property
__________________
Message boards: The only place where multiple personality disorders are treated with a "welcome" post.
Kodo is offline   Reply With Quote
Old 12-08-2005, 05:54 AM   #3
The Stoat
The Grim Squeaker
 
The Stoat's Avatar
 
Join Date: May 2004
Posts: 239
Thanks: 0
Thanked 1 Time in 1 Post
The Stoat is on a distinguished road
Quote:
Originally Posted by Kodo
if you do that then the value of one will remain in the controls viewstate each time because when you post back to the page, the value is reset to its' base of 0. So it won't increment. What you need to do is put the value in viewstate so that you can return it later if the initial value is 0.

So you would something like this to persist the value.


Code:
Public Property inc() As Integer
        Get
            Return ViewState("inc")
        End Get
        Set(ByVal value As Integer)
            ViewState("inc") = value
        End Set
    End Property
That is just the job cheers

__________________
το χιούμορ είναι εκπαιδευμένη αυθάδεια -Αριστοτέλης

They that approve a private opinion, call it opinion; but they that dislike it, heresy; and yet heresy signifies no more than private opinion, - Thomas Hobbes
The Stoat is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Monitor Global Variable Crilen007 General 1 03-08-2005 03:26 PM
public variable resetting themselves to "" ? why paulmcdonnell Modules & VBA 5 04-23-2004 09:10 AM
[SOLVED] Variable Graph Values Markie Reports 1 11-05-2002 06:59 AM
Passing variable values Stuart Green Modules & VBA 3 07-08-2002 07:03 AM
Displaying Variable Values currie Reports 0 06-19-2001 11:21 AM




All times are GMT -8. The time now is 10:58 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Sponsored Links

How to advertise

Media Kit


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World