Can't set session variables

M

Magnus Blomberg

Hello!

I'm quite new to ASP.Net and trying to send a variable from one page to
another.

Om my first page, Index.htm page I have a link as:
<a href="Default.aspx?MyID=7">Def 7</a>

On Default.aspx I have following code in the load event:
Label1.Text = "MyID=" + Convert.ToString( Page.Session["MyID"]);

I really think it would work, but I only get the text MyID=.
Is the <a> tag not setting a session variable?

Any ideas
/Magnus
 
J

Joyjit Mukherjee

Hi,

what you're doing here is with QueryString, not session objects. In that
case, your second line would look like: -

Label1.Text = "MyID=" + Convert.ToString( Request.QueryString["MyID"]);

Or else, if you want to use ASP.NET session object, set the session object
in the first page as follows :-

if (!PostBack)
{
Page.Session["MyID"] = 7;
}

then call it from the second page :-

Label1.Text = "MyID=" + Convert.ToString( Page.Session["MyID"]);

Regards
Joyjit
 
E

Eliyahu Goldin

It is not. Why should it? You can get the parameter with
Request.Params["MyID"].

Eliyahu
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top