Using variables across multiple Web Forms

  • Thread starter Thread starter Brian Conway
  • Start date Start date
B

Brian Conway

I am trying to use a variable from a login page web form (username) to build
a select statement in another web form. How do I pass the variable from one
form to the other and then insert that variable into my select statement? I
thought setting it as a public variable would do it, but that is not
working, unless I have it in the wrong place. Currently it is in the class
area.
 
Brian,

You can't do this. The reason is that pages in ASP.NET don't know about
other objects that called them. The best you could do is pass a value in
the session object which you can pull from the new page.

Hope this helps.
 
depends on your exact situation, you can use session state, application state, cache, HttpContext.Items, view state, query string or cookies to pass information between pages/postbacks

----- Brian Conway wrote: ----

I am trying to use a variable from a login page web form (username) to buil
a select statement in another web form. How do I pass the variable from on
form to the other and then insert that variable into my select statement?
thought setting it as a public variable would do it, but that is no
working, unless I have it in the wrong place. Currently it is in the clas
area
 
oh yeah, if you use server.transfer, you can also get the reference to the first page through HttpContext.Handler, cast it to a Page object and you can access the public properties, I usually don't use it though because I find HttpContext.Items is a lot cleaner for passing small bits of information in 1 continous request

----- Daniel Jin wrote: ----


depends on your exact situation, you can use session state, application state, cache, HttpContext.Items, view state, query string or cookies to pass information between pages/postbacks

----- Brian Conway wrote: ----

I am trying to use a variable from a login page web form (username) to buil
a select statement in another web form. How do I pass the variable from on
form to the other and then insert that variable into my select statement?
thought setting it as a public variable would do it, but that is no
working, unless I have it in the wrong place. Currently it is in the clas
area
 
Can you give me an example of how to use the session state. I want to pass
the variable, but I do not want to pass it through the URL.


Daniel Jin said:
depends on your exact situation, you can use session state,
application state, cache, HttpContext.Items, view state, query string or
cookies to pass information between pages/postbacks.
 
Session["username"] = strUsername

on the page that you want to retrieve the session variable:

string strUser = Session["username"].toString();

Be careful though, the session variables will expire after a certain amount
of time.
 
Back
Top