Priyanka Chandok
Priyanka Chandok

Reputation: 215

Object reference not set to instance of an object

I have a web form which works fine until you keep on working on it. But if you leave it for 20 mins, on submit button click it gives the following error

enter image description here Error

It seems to me the page request object gets NULL but exactly cant reach to the issue. I have tried to increase the session timeout at IIS but it did not help.

Please help me to know the root cause for it.

Thanks all

Upvotes: 0

Views: 2099

Answers (2)

Anyname Donotcare
Anyname Donotcare

Reputation: 11393

Try to make a check on the page load event:

for example:

 protected void Page_Load(object sender, EventArgs e)
        {

            if (Session["emp_num"] != null)
            {
                empNum = int.Parse(Session["emp_num"].ToString());
            }
            else
            {
                //Go To The Home Page(Login Page)
            }
        }

You can make this check in the Masterpage.cs

Upvotes: 0

Fredrik Mörk
Fredrik Mörk

Reputation: 158309

Without seeing some code one can only guess, but I think that btnSubmit_Click tries to use an object that is stored in the Session. Because of the long idle time, the session has timed out, and clicking the button causes the request to get a new session, in which this object is not yet assigned.

Upvotes: 3

Related Questions