Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi All,

i am getting this error sometime on submit button click and it will stop the insert option and throw this error message...please suggest me some solution.
Error message is given below.

System.NullReferenceException: Object reference not set to an instance of an object. at main.btnSubmit_Click(Object sender, EventArgs e) in c:\Inetpub\wwwroot\Test\main.aspx.cs:line 536 at System.Web.UI.WebControls.Button.OnClick(EventArgs e) at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Posted
Updated 8-Jul-12 19:25pm
v2
Comments
Sebastian T Xavier 9-Jul-12 1:26am    
If you post your code, we have better chance to analyse your problem.
Sander Rossel 9-Jul-12 1:27am    
Please show us the code of your Button.Click Event.
You are making calls to an object that is not initialized. There is no way for us to tell you which object it is.

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.
 
Share this answer
 
Comments
AshishChaudha 9-Jul-12 2:07am    
my 4!
1. Check your connection whether it is open or closed.
2. Check your query and the objects whether they are initialized or not.
3. Check your query by using Debugger.


There are many reasons when "Object reference not set to an instance of an object" appear.

Show us the code of your submit button so that the question will be more clear, and easy to help you out. click on "improve queston"


Thanks
Ashish
 
Share this answer
 
Use Debugger option or debug each line in the submit button function to check which line is throwing the Error. Try to backtrack !
 
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