ASP.NET - Sessions urgent

Asked By sachin s
11-Feb-12 01:20 PM

hi,
I have used 3 pages, wherein i have used sessions for storing the values in 1st & 2nd page.
i want the values to b displayed in the 3rd page in a textbox ctrl.

1st page(drop down connected to SQL 2000):
i have used the foll code Session["source"] = dt.Rows[0]["source"].ToString();
2nd page :protected void TextBox1_TextChanged(object sender, EventArgs e)
    {
    Session["name"] = TextBox1.Text;
    } 3rd page : TextBox1.Text = (Session["source"]).ToString(); For the above code, i get "

"Object reference not set to an instance of an object".

Pls advice.
Sachin

  dipa ahuja replied to sachin s
11-Feb-12 02:22 PM
The error is coming because session contains null value

always check session before using it for ex:

if(Session["use"] != null)
{
  string user=Session["user"].ToString();
}
  Danasegarane Arunachalam replied to sachin s
12-Feb-12 01:02 AM
1.Did you debug the code.
2.Does the code
Session["source"] = dt.Rows[0]["source"].ToString();

assign any value to the session ?

3.And also you are setting the session in the keypress event of text box

Session["name"] = TextBox1.Text;

Which may not stored

  D Company replied to sachin s
12-Feb-12 01:32 AM
Hello sachin.

as suggested in previous posts , first thing u have to check whether ur session is null or not than assign it.
second thing that u can do here is check your session variables value on page load, and see if u get any value. m sure u will not.

third thing define your session variable globally, and yes put breakpoints

hope it helps!!
regards
D
Create New Account
help
www.teresablanco.com / Listing / VirtualTour.aspx?ListingID = 958035< / VirtualTourUrl> <Location> <GeoArea id = "207550" type = "Neighborhood" name = "Midtown" / > <GeoArea id = "44569" type = "City" name = "Atlanta" / > <GeoArea id = "289" type = "State" name = "Georgia" abbreviation = "GA" / > <GeoArea id = "44" type = "Country" name = "United States" abbreviation = "US" / > <Address publiclyVisible = "true" suite = "1505"> 120 Ralph McGill Blvd< / Address> <PostalCode p2a / listing / 8842 / 1168 / 8e2b / e709c93a42ec0f0a5eb5 / w64h48.jpg< / Url> < / Item> < / Media> <ListingAgent> <AgentID> 216636< / AgentID> <Name> Teresa Blanco< / Name> <ContactInfo> <Telephone name = "Work"> 404-664-4927< / Telephone> <WebSite> http: / / www.teresablanco.com< / WebSite> <ProfileUrl> http: / / NLS.point2 point2.com / p2a / agency / bf4c / 9c4b / 9561 / 638f22f013dbc6597213 / w160h120.jpg< / Url> < / Item> < / Media> < / ListingAgent> <Broker> <Name> Blue Sky Real Estate Group< / Name> < / Broker> < / Listing> <Listing> <ListingID> 958041< / ListingID> <RegionalMLSNumber publiclyVisible = "1
Net hi friends Any one send frequently asked Important questions in C# .Net, ADO .Net, Asp .Net and Sql Server. . . . . . . . tx in Advance. . . . . . Hi, Find this. . (B)What is an IL? (B A) What is scavenging? (B) What are different types of caching using cache object of ASP.NET? (B) How can you cache different version of same page using ASP.NET cache object? (A) How will implement Page Fragment Caching? (B) Can you compare ASP.NET sessions with classic ASP? (B) Which are the various modes of storing ASP.NET session
in Sql server as var_name int How do you separate business logic while creating an ASP.NET application? There are two level of asp.net debugging 1. Page level debugging For this we have to edit the page level debugging open Visual Studio .NET and begin a new C# Windows Control Library. 2) You may name it whatever you like, for this sample the project name will be CalenderControl Using the Calender Control in a Windows Application It’s just like The control itself will take care of the date display How can you deploy an asp.net application ? You can deploy an ASP.NET Web application using any one of the following
how to session useful in web how to session useful in web plz send me details with code in vb best benifit of the session is user based mean u can differentiate login user in different way • Process independent. ASP.NET session state is able to run in a separate process from the ASP.NET host process. If session state is in a separate process, the ASP.NET process can
share session between Classic ASP applications and ASP.NET applications? I want to share session state between Classic ASP applications and ASP.NET applications. Can we share ? if yes , How ? Yes, it can. See the article at the frame = true Cookies are the most common way for Web applications to identify the user session, and can be used to identify session state for both classic ASP and ASP.NET. Session state information is stored in memory