Click here to Skip to main content
15,894,405 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
am using session variables to store the value and accessing it in another form
C#
string name= Session["id"].ToString();
           Session["load"] = "2";
           Response.Redirect("sss.aspx");

the name has the value of session variable
in the sss.aspx form page load event
C#
Label1.Text = Session["id"].ToString();

this code throws an exception of "Object reference not set to an instance of an object"

i was just confused of the session variables.where am doing wrong.lots of thanks in advance.
Posted
Comments
[no name] 16-May-13 4:29am    
Send me code where your are going to assign Session["id"] value before page redirect.

My view is your not assigning value to id session variable. Please check out the code.

1 solution

hi RAGUNATH V,

Do you have 2 Session objects..? If not do the below.

Instead of Session['load'], please use Session['id'] = '2';

Thank you,
Vamsi
 
Share this answer
 
v2
Comments
RAGUNATH V 16-May-13 4:02am    
session['load'] is another session variable.am having problem with session["id"]
RelicV 16-May-13 4:05am    
Right, thought so. Could you provide the page load of sss.aspx page..?
RAGUNATH V 16-May-13 4:14am    
protected void Page_Load(object sender, EventArgs e)
{

Conn = new SqlConnection(ConnString);
string retriveString = "Select User_id,ID from Administration where User_id = '" + Session["id"].ToString()+ "' AND Designation='Rad'";
cmd = new SqlCommand(retriveString, Conn);
Conn.Open();
SqlDataReader red = cmd.ExecuteReader();
if (red.Read())
{
Session["dname"] = red[1].ToString();
}
Conn.Close();
Label1.Text = Session["id"].ToString();
}
RelicV 16-May-13 4:17am    
Then use Server.Transfer() instead of Response.Redirect().

Please go through the below link for more clarification.
http://weblogs.asp.net/bleroy/archive/2004/08/03/Don_2700_t-redirect-after-setting-a-Session-variable-_2800_or-do-it-right_2900_.aspx

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