Click here to Skip to main content
15,886,737 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Error:-
Object reference not set to an instance of an object.

Source Error:
C#
CheckBox cBox = (CheckBox)contact.FindControl("cbSelect");  //here it gives error...
           if (cBox.Checked)
           {


Plz Help me to solve this error.....
Posted
Updated 15-Jun-12 19:30pm
v2
Comments
Tejas Vaishnav 16-Jun-12 0:50am    
please provide proper code so we can check why you should get this type of error.
hitech_s 16-Jun-12 2:38am    
provide code in .aspx page
Yatin chauhan 16-Jun-12 2:48am    
your checkbox return null value thats y its give error. plz debuge and check that.

Object reference not set to an instance of an object
This error happens when you try to use a property or call a method of an object that is null. More details: here[^]

A simple use of Visual studio DEBUGGER can tell you the object because of which it is happening. Just look at the stack trace and put a debugger on that line. Check the objects of that line and see if any one is null and you are trying to use that objects property. Handle the same.


For now, error in line below
CheckBox cBox = (CheckBox)contact.FindControl("cbSelect");

means that there was no control named 'cbSelect' in the 'contact' object. contact.FindControl("cbSelect") returned null. Now, when you try to cast it into CheckBox, it throw error.

Verify that the name is correct and exists in the control object contact. Put a null check too.
 
Share this answer
 
Hi,

First of all let me tell you one thing that your code is unable to find your control. What is "contact" actually? any place holder or any panel or any form?

Follow the links given to find your answer:
http://odetocode.com/articles/116.aspx[^]
http://msdn.microsoft.com/en-us/library/486wc64h.aspx[^]

All the best.
 
Share this answer
 

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