What is so special about Page_Load?

We set session variables in Page_Load and then immediately redirected to another page before Page_Load completed.

When we got to the new page, the new page didn't see the session vars we set.

Is there something about Page_Load() where certain functionality is not available, such as session vars etc? Anything else that is tricky or unique about Page_Load()?

LVL 1
rascalAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

wdfdo1986Commented:
can I see your code before comment
0
chandrasekar1Commented:
no, you can easily set session in page_load event and access it in any other pages inside the application

example code:

Main page
protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Session.Add("somename", "newpageasavalue");
                Response.Redirect("about.aspx", false);
                return;
            }
        }

Open in new window


about.aspx
 protected void Page_Load(object sender, EventArgs e)
        {
            string NameSessionValue = string.Empty;
            if (Session["somename"] != null)
                NameSessionValue = Convert.ToString(Session["somename"]);
                // You can get the value in NameSessionValue string
        }

Open in new window



Note : i think you well know about the session timeout, if you not, once the session is timeout, Session["somename"] will be destroyed, you cant access it.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rascalAuthor Commented:
I noticed your code has a "return" statement after the redirect. My code did not. I assumed that the redirect preluded the need for the return, but is it possible the lack of a return (or in my case an exit sub statement since I'm in VB) was the culprit?
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

EyalCommented:
the return is not mandatory here

I recommand doing it witht he following lines

HttpContext.Current.Response.Redirect(Url,false);
HttpContext.Current.ApplicationInstance.CompleteRequest();
HttpContext.Current.Response.End();

Open in new window

0
wdfdo1986Commented:
Try Server.Transfer instead of Response.Redirect
0
rascalAuthor Commented:
Thank you all for the helpful responses.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.