Connecting Tech Pros Worldwide Forums | Help | Site Map

Variables

Keith
Guest
 
Posts: n/a
#1: Jul 19 '05
I have a number of form fields that I wish to temporarily record into
variables and pass to a small number of subsequent pages.

Is the best way to save each one to a session variable when I submit the
form and then to clear the variables when I no longer need them?

Also, if this is the best method, what is the code for saving a form field
to a session variable when the form has not yet been submitted. For
example, when I submit Form1, I want the contents of Field1 to be entered
into SessionVariable1 and then the form to be submitted as normal.



J. Baute
Guest
 
Posts: n/a
#2: Jul 19 '05

re: Variables



I don't really get what you're trying to do here exactly, but are you trying
to "save" certain form values and automatically re-use those in several
forms?

"Keith" <@.> wrote in message news:#j1ziDBEEHA.688@tk2msftngp13.phx.gbl...[color=blue]
> I have a number of form fields that I wish to temporarily record into
> variables and pass to a small number of subsequent pages.
>
> Is the best way to save each one to a session variable when I submit the
> form and then to clear the variables when I no longer need them?
>
> Also, if this is the best method, what is the code for saving a form field
> to a session variable when the form has not yet been submitted. For
> example, when I submit Form1, I want the contents of Field1 to be entered
> into SessionVariable1 and then the form to be submitted as normal.
>
>[/color]


Peter Foti
Guest
 
Posts: n/a
#3: Jul 19 '05

re: Variables


"Keith" <@.> wrote in message news:%23j1ziDBEEHA.688@tk2msftngp13.phx.gbl...[color=blue]
> I have a number of form fields that I wish to temporarily record into
> variables and pass to a small number of subsequent pages.
>
> Is the best way to save each one to a session variable when I submit the
> form and then to clear the variables when I no longer need them?
>
> Also, if this is the best method, what is the code for saving a form field
> to a session variable when the form has not yet been submitted. For
> example, when I submit Form1, I want the contents of Field1 to be entered
> into SessionVariable1 and then the form to be submitted as normal.[/color]

Session variables occur server side, thus, you MUST submit the form before
they can be put into session variables. The page that the form gets
submitted to (the action attribute of the form) could put the values into
session variables. Assuming your form has method post, and you have inputs
named "foo" and "bar", your form handler could do something like this:

<%
Session("foo") = Request.Form("foo")
Session("bar") = Request.Form("bar")

Response.Write "<div>Session(""foo"") = "
Response.Write Session("foo")
Response.Write "</div>"
Response.Write "<div>Session(""bar"") = "
Response.Write Session("bar")
Response.Write "</div>"
%>

Regards,
Peter Foti


Phillip Windell
Guest
 
Posts: n/a
#4: Jul 19 '05

re: Variables


You submit the form as normal, but on the page it is submitted to is where
you add the values to the Session Variables.

Coding "off the cuff" is dangerous for me but it would look something like
this on the second page. If the Session Variable is called "Person" and the
form field is called "MyName" then:

Session("Person") = Request.Form("MyName")

From here it will stay in the Session Variable as long as the Session is
alive or until you change it to some other value. It will be available to
any page at anytime after that as long as it is the same Session.

To retreive it into a variable:
strMyString = Session("Person")
To display it in the browser:
Resonse.write Session("Person")


--

Phillip Windell [MCP, MVP, CCNA]
www.wandtv.com


"Keith" <@.> wrote in message news:#j1ziDBEEHA.688@tk2msftngp13.phx.gbl...[color=blue]
> I have a number of form fields that I wish to temporarily record into
> variables and pass to a small number of subsequent pages.
>
> Is the best way to save each one to a session variable when I submit the
> form and then to clear the variables when I no longer need them?
>
> Also, if this is the best method, what is the code for saving a form field
> to a session variable when the form has not yet been submitted. For
> example, when I submit Form1, I want the contents of Field1 to be entered
> into SessionVariable1 and then the form to be submitted as normal.
>
>[/color]


Keith
Guest
 
Posts: n/a
#5: Jul 19 '05

re: Variables


Yes. I am trying to save the values of several form fields and reuse them,
but wanted to know if there was a way of saving them without submitting the
form. I know I can use session variables, but wondered if other types of
variables existed that may suite better etc.

"J. Baute" <WUPYRDEDAWJD@spammotel.com> wrote in message
news:405f0c7e$0$319$ba620e4c@news.skynet.be...[color=blue]
>
> I don't really get what you're trying to do here exactly, but are you[/color]
trying[color=blue]
> to "save" certain form values and automatically re-use those in several
> forms?
>
> "Keith" <@.> wrote in message news:#j1ziDBEEHA.688@tk2msftngp13.phx.gbl...[color=green]
> > I have a number of form fields that I wish to temporarily record into
> > variables and pass to a small number of subsequent pages.
> >
> > Is the best way to save each one to a session variable when I submit the
> > form and then to clear the variables when I no longer need them?
> >
> > Also, if this is the best method, what is the code for saving a form[/color][/color]
field[color=blue][color=green]
> > to a session variable when the form has not yet been submitted. For
> > example, when I submit Form1, I want the contents of Field1 to be[/color][/color]
entered[color=blue][color=green]
> > into SessionVariable1 and then the form to be submitted as normal.
> >
> >[/color]
>
>[/color]


J. Baute
Guest
 
Posts: n/a
#6: Jul 19 '05

re: Variables



"Keith" <@.> wrote in message news:#c5asEGEEHA.1600@tk2msftngp13.phx.gbl...[color=blue]
> Yes. I am trying to save the values of several form fields and reuse[/color]
them,[color=blue]
> but wanted to know if there was a way of saving them without submitting[/color]
the[color=blue]
> form. I know I can use session variables, but wondered if other types of
> variables existed that may suite better etc.[/color]

Storing the values in cookies are anothother possibility, but frankly I'd go
for the Session object anyway.

You could also set cookies from ASP when the form is posted, but in that
case you can just as well use the session object, which also uses a cookie
but the data can't be retrieved from it clientside. Or you can set cookies
straight from JavaScript before your form is posted.




Keith
Guest
 
Posts: n/a
#7: Jul 19 '05

re: Variables


Thank you

I think I will stick with session variables like I had thought in the first
place then.

I will just make a point of clearing them when I have finished with them so
there are not unnecessary ones during a session.

Do these variables have any impact on performance and resources does anyone
know?


"J. Baute" <WUPYRDEDAWJD@spammotel.com> wrote in message
news:405feace$0$777$ba620e4c@news.skynet.be...[color=blue]
>
> "Keith" <@.> wrote in message[/color]
news:#c5asEGEEHA.1600@tk2msftngp13.phx.gbl...[color=blue][color=green]
> > Yes. I am trying to save the values of several form fields and reuse[/color]
> them,[color=green]
> > but wanted to know if there was a way of saving them without submitting[/color]
> the[color=green]
> > form. I know I can use session variables, but wondered if other types[/color][/color]
of[color=blue][color=green]
> > variables existed that may suite better etc.[/color]
>
> Storing the values in cookies are anothother possibility, but frankly I'd[/color]
go[color=blue]
> for the Session object anyway.
>
> You could also set cookies from ASP when the form is posted, but in that
> case you can just as well use the session object, which also uses a cookie
> but the data can't be retrieved from it clientside. Or you can set cookies
> straight from JavaScript before your form is posted.
>
>
>
>[/color]


J. Baute
Guest
 
Posts: n/a
#8: Jul 19 '05

re: Variables



"Keith" <@.> wrote in message news:OV$roXLEEHA.3980@TK2MSFTNGP09.phx.gbl...[color=blue]
> Thank you
>
> I think I will stick with session variables like I had thought in the[/color]
first[color=blue]
> place then.
>
> I will just make a point of clearing them when I have finished with them[/color]
so[color=blue]
> there are not unnecessary ones during a session.
>
> Do these variables have any impact on performance and resources does[/color]
anyone[color=blue]
> know?[/color]

Since session variables are stored in memory, storing a lot of them for
every users session could lead to performance issues concerning your memory
use.
Remember that your session doesn't end when a user quits his browser app.
That session will still be in memory until it times out serverside, so it's
definatly a good idea to free those form variables if you don't need them
anymore to free up some memory.



Closed Thread