variable persistence

G

Guest

hey all,

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

thanks,
rodchar
 
S

S. Justin Gengo

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
 
G

Guest

how do i store a client-side variable in viewstate or session? i'm not sure
of the exact syntax to do this?
 
S

S. Justin Gengo

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
 
S

S. Justin Gengo

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
 
P

Patrice

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).
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,244
Latest member
cryptotaxsoftware12

Latest Threads

Top