Click here to Skip to main content
13,708,336 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
object refrence not set what is the issue in else staetment getting issue


What I have tried:

<pre>                if (Request.Cookies["aa"] == null)
                {
                    Response.Cookies["aa"].Value = product_name.ToString() + "," + product_desc.ToString() + "," + product_price.ToString() + "," + product_qty.ToString() + "," + product_images.ToString() + "," + data_id.ToString();
                    Response.Cookies["aa"].Expires = DateTime.Now.AddDays(1);

                }
                else
                {
                    Response.Cookies["aa"].Value = Request.Cookies["aa"].Value.ToString() + "|" + product_id.ToString() + "," + product_name.ToString() + "," + product_desc.ToString() + "," + product_price.ToString() + "," + product_qty.ToString() + "," + product_images.ToString() + "," + data_id.ToString();
                    Response.Cookies["aa"].Expires = DateTime.Now.AddDays(1);

                }
Posted 9-Dec-17 23:20pm
Updated 10-Dec-17 5:08am
Comments
Mehdi Gholam 10-Dec-17 5:42am
   
Debug your code and see which object is null.
Waqaskhan121 11-Dec-17 0:41am
   
Thanks a lot finally solved it by debuggig

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Quote:
object refrence not set what is the issue in else staetment getting issue

This is not a problem in source code, this a problem at runtime, and we can't do anything for you.
Your only solution is using the debugger and inspect variables/objects at point of failure.

There is a tool that allow you to see what your code is doing, its name is debugger. It is also a great learning tool because it show you reality and you can see which expectation match reality.
When you don't understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.

Debugger - Wikipedia, the free encyclopedia[^]
Debugging C# Code in Visual Studio - YouTube[^]
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to.
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web01-2016 | 2.8.180920.1 | Last Updated 10 Dec 2017
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100