2 Replies - 1665 Views - Last Post: 02 July 2014 - 12:53 PM Rate Topic: -----

#1 donald.fisher   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 19-June 14

Persistent Variables?

Posted 19 June 2014 - 12:35 AM

Seeking guidance concerning persistence (or lack thereof) of variables in an ASP.NET page coded in VB. Specifically, several Double-type variables and a String-type Array.

<script runat="server">

Public strResults(9) As String
Public dblNum1 As Double
Public dblNum2 As Double
Public dblResult As Double

Protected Sub SomeSub1() Handles btnSomeButton.Click
     ' Actions etc.
     ' Assign values from two TextBox controls to dblNum1 and dblNum2
     ' Perform calculation (e.g., add, subtract) and assign result to dblResult
     ' Display result of calculation in another TextBox control
End Sub

Protected Sub SomeSub2() Handles btnSave.Click
     ' Actions etc.
     ' Save calculation to strResults Array (after SomeSub1 is run the values all return zero)
End Sub


I've attempted to explain as brief as possible. Basically, when SomeSub1 runs performing a calculation and displaying the results and then SomeSub2 runs the variables are all containing zero values. How to retain variable values?

Thank you.

Is This A Good Question/Topic? 0
  • +

Replies To: Persistent Variables?

#2 baavgai   User is offline

  • Dreaming Coder
  • member icon

Reputation: 7181
  • View blog
  • Posts: 14,969
  • Joined: 16-October 07

Re: Persistent Variables?

Posted 19 June 2014 - 03:35 AM

Take a look at Session: http://msdn.microsof...=vs.100%29.aspx

Understand that in ASP.NET, or any web framework, your page is "stateless" because HTTP is. As user asks a server for a page, the page is given, end of transaction. Obviously, this makes any kind of sequential flow impossible. This is why "cookies."

The solution is to use a session concept. That is, a persistent set of key value pairs provided to the page based on if it believes this part of a previous request. A cookie does this, though another mechanism that tacks a session id on the URL is also used. However, using Session means not caring about cookies: it's an abstraction.

It's pretty important to understand the session concept in web programming. Web programming is not rich client programming; it's messy and disconnected. Many rich client best practices are simply not viable in web world.
Was This Post Helpful? 0
  • +
  • -

#3 Zick Boy   User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 33
  • Joined: 30-October 08

Re: Persistent Variables?

Posted 02 July 2014 - 12:53 PM

I think your best option is to use the ViewState to store the value.

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1