Saturday 9 October 2010

Ajax ComboBox Object reference not set to an instance of an object.

I was getting the following error after completing an operation in a web application and trying to click a link to enter a new Invoice on the same page.

This turned out to be due to one of the combo boxes trying to load its postback data (because I was navigating to the same page). The reason the error was being thrown is because I disabled the controls on the form and if they are disabled then the Ajax Combo box cannot load its post back data.

One work around would be to Response Redirect to another page after the invoice is posted. This way the controls would not try to load postback data again.

Removing the method to disable the controls also stopped the issue so replacing the combo box with a text box was a simple work around.

Just to re iterate its the control being disabled that has caused the problem when the control is trying to load the postback data.

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:





An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:





[NullReferenceException: Object reference not set to an instance of an object.]
   AjaxControlToolkit.ComboBox.LoadPostData(String postDataKey, NameValueCollection postCollection) +106
   AjaxControlToolkit.ComboBox.System.Web.UI.IPostBackDataHandler.LoadPostData(String postDataKey, NameValueCollection postCollection) +36
   System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad) +693
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1743

No comments:

Post a Comment