Click here to Skip to main content
15,901,505 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I am trying to Session over my categoryName over to the next page when clicked on the LinkButton. However, when i debug my codes, it didnt go inside the if statement and skipped it. I do not know what exactly the problem is. Have i gone wrong anywhere?

Here is my .cs code for the first page:

C#
categoryName.Text = Session["categoryName "].ToString();
        Response.Redirect("Category2.aspx");


Here is my .cs code for the second page (I place this code in Page_Load):

C#
protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["categoryName "] != null)
        {
            categoryName .Text = Session["categoryName "].ToString();
        }
    }
Posted
Updated 28-Jul-12 22:53pm
v2

You never set the session value. To set a session value:
C#
Session["name"] = value;
 
Share this answer
 
Comments
kellycx 29-Jul-12 5:27am    
But my session value is I get from database. So if i set a value to it, am i hard coding it?
StianSandberg 29-Jul-12 5:51am    
If you get a value from database you still have to set the session variable:
Session["categoryName"] = valueFromDatabase;
Declare a variable.

string CategoryName=//something. get from database;


Before clicking on linkbutton or in link button click
set
C#
Session["categoryName"]=CategoryName;
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900