variable persistence

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hey all,

is there a way to persist a client-side variable between postbacks?

thanks,
rodchar
 
Rodchar,

You may store it in a cookie, in a database, in a text file, in viewstate,
or in a session variable. Which is the best would depend on the information
being stored.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
how do i store a client-side variable in viewstate or session? i'm not sure
of the exact syntax to do this?
 
rodchar,

To store in viewstate:

Viewstate.Add("MyString", "This is my variable")
Viewstate.Add("MyInt", 13)

To store in session:

Session.Add("MyString", "This is my variable")
Session.Add("MyInt", 13)

Where MyString and MyInt are the keys and then any object may be added as
the value.

To retrieve:

Dim MyString As String = Viewstate.Item("MyString").toString
Dim MyInt As Int32 = CType(Viewstate.Item("MyInt"), Int32)

Dim MyString As String = Session.Item("MyString").toString
Dim MyInt As Int32 = CType(Session.Item("MyInt"), Int32)
--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
Yes,

But if he posts back... It's no longer just client side is it? So what's the
point of limiting it to client side then? I'm just trying to understand why
not use a "server side solution". Of course if the variable needs to be
accessed again client-side then you're right, a hidden field or a cookie is
about the only choice. (Unless you get into Ajax).

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
Using an hidden field you can transmit back and forth the value...

Where do you need this exactly ? (you could use a cookie if you need this
only client side and find this acceptable).
 
to store my javascript variable in viewstate, i had to use an html hidden
textbox which i converted to run at server and that seem to have work well,
thanks.

rodchar
 
Back
Top