ASP.NET - sessions**URGENT*

Asked By sachin s
11-Feb-12 12:55 PM
hello,

Object reference not set to an instance of an object.


could any1 pls tell me what the above err means.


kind regards
Sachin




  kalpana aparnathi replied to sachin s
11-Feb-12 01:05 PM
public class Class1
{
         
public string mymethod()
   
{
       
HttpContext.Current.Session["MySession"] = "xyz";
       
return HttpContext.Current.Session["MySession"].ToString();
   
}
}

now in code behind create an instance of class1 call the method and see the output as xyz.

try this code on page_load event

       Class1 cx = new Class1();
       Response.Write(cx.mymethod());

i think you should debug your application.or show me you class file code and

place where you are trying to use this session.


hope that helps.

  dipa ahuja replied to sachin s
11-Feb-12 01:11 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();
}

  sachin s replied to kalpana aparnathi
11-Feb-12 01:13 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






  kalpana aparnathi replied to sachin s
11-Feb-12 01:21 PM
try this way in 3rd  page:

TextBox1.Text = Session["source"].ToString();

  Somesh Yadav replied to sachin s
12-Feb-12 03:43 AM
Hi,

Session("Cart") is null
So either check if Session("Cart") is null, and create a new one if it doesnt exists. or create a new Session("Cart") when the session is started.

Session("Cart") = New Cart

even you can also try for this

Session("Cart") is not initialized yet. So make sure You need to check Session("Cart") with null(nothing) and assign it properly. You need to do something like this.

Dim cart As New Cart
cart = Session("Cart")
if (cart == Nothing)
cart = new cart();

then use cart object. you won't get this type of error.
  Suchit shah replied to sachin s
13-Feb-12 02:08 AM
This error means is that : "The code is trying to access a member of a reference type variable that is set to null."

So you are assigning some value which is NULL so check the condition
Create New Account
help
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 How can we know a state of a thread? (A) What is use of Interlocked class ? (A) What is a monitor object? (A) What are wait handles? (A) What is ManualResetEvent and Webservices (B)What is an application domain? (B) What is .NET Remoting? (B) Which class does the remote object has to inherit? (I) what are two different types of remote 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
cannot be used with indexers, destructors, or types. In C#, the static keyword indicates a class variable. In VB, the equivalent keyword is Shared. Its scoped to the class in which it occurs. Example a. Static int var / / in c#.net b. static void 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 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
Migration from ASP to ASP.net How to convert ASP site to ASP.NET site using C# http: / / www.asp.net / downloads / archived-v11 / migration-assistants / asp-to-aspnet hi, ASP.NET framework is very much different from unstrucured ASP and there is no correct way to
Tracing in ASP.NET? hi all, what is tracing? how to achieve tracing in asp.net? different ways of doing tracing? thanks and regards Aman Khan hi. . Tracing in ASP.NET 2.0 Tracing is a way to monitor the execution of your ASP.NET application. You can record exception details and program flow in a way that doesn't
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 come and go while the session state process remains available. Of course, you ASP, too. • Support for server farm configurations. By moving to an out-of-process model, ASP.NET also solves the server farm problem. The new out-of-process model allows all servers