PDA

View Full Version : sending a variable from one aspx form to another



TheTempest
09-08-2005, 09:07 AM
^ subject.

damnit! I lost my code snippit on how to do this. I thought If found it on the dotnetjunkies domain, but I was unable to find it.

Does anyone know how to send a variable (or the value of it) to another page?

Thanks

Bilago
09-08-2005, 09:13 AM
In asp.net if u want to pass a variable from one page to another page it is better to use response.redirect method or sessions or cookies.

using response.redirect
response.redirect("page2.aspx?var1="<value of variable such as textbox1.text or 56>)

in page 2 use the following code to retrive the value

if request.querystring("var1")="" then
'checking for null value
response.redirect("page1.aspx")
else
variable2=request.querystring("var1")
endif
now the value you passed from page 1 is in variable2

ok same way u can use session variables also
in page1.aspx
session("var1")=textbox1.text or "56"

in page2.aspx
variable2=session("var1")
'now variable2 contains the value
i am not good at cookies so i am not mentioning here

also if u want data security might want to use Context.Handler instead.

MarcX
09-08-2005, 09:25 AM
Um yeah...

There's several ways to get data from one page to another, and he pretty much listed them:

- through the url
- through cookies
- through post variables

NAATYE
09-08-2005, 09:44 AM
Session object is also a viable solution.

Bilago
09-08-2005, 09:48 AM
ok same way u can use session variables also
in page1.aspx
session("var1")=textbox1.text or "56"

in page2.aspx
variable2=session("var1")
'now variable2 contains the value
i am not good at cookies so i am not mentioning here

also if u want data security might want to use Context.Handler instead.

all ready covered that :)

NAATYE
09-08-2005, 10:39 AM
all ready covered that :)
Sorry about that... missed that. :cry:

TheTempest
09-08-2005, 11:09 AM
Thanks guys.