Object reference not set to an instance of an object.

  • Thread starter Microsoft News Group
  • Start date
M

Microsoft News Group

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.



decimal price =
decimal.Parse(((TextBox)PropertyGridView.FooterRow.FindControl("PriceTextBox")).Text);

Any clue why this is happening?



Stack Trace:

[NullReferenceException: Object reference not set to an instance of an
object.]
AllProperies.PropertyGridView_RowCommand(Object sender,
GridViewCommandEventArgs e) in c:\Documents and Settings\Flynn\My
Documents\My Webs\CVM Web Portal\AllProperies.aspx.cs:70
System.Web.UI.WebControls.GridView.OnRowCommand(GridViewCommandEventArgs
e) +75
System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean
causesValidation, String validationGroup) +76
System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source, EventArgs
e) +88
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source,
EventArgs e) +117
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +86
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String
eventArgument) +153
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +172
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4919
 
K

Karl Seguin [MVP]

Best guess is that FindControl is failing to find a control wth the id of
"PriceTextBox" so ur getting a null object back.

Of course, the other option is that PropertyGridView.FooterRow is null...

Karl
 
S

sloan

When you're dealing with nulls/nothings, my advise is to break it down into
each piece, then rewrite the uber-single statement.

something like

FooterRow fr = PropertyGridView.FooterRow;
object o = fr.FindControl("PriceTextBox");
TextBox tb = (TextBox)o;
string s = tb.Text;
decimal price = decimal.Parse(s);


You'll usually find it that way.

Its not bad to put a
if(null!= someObject)
{
//do something//
}

in once a while too.




decimal price =decimal.Parse(((TextBox)PropertyGridView.FooterRow.FindControl("PriceTextBox
")).Text);

Microsoft News Group said:
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.



decimal price =
decimal.Parse(((TextBox)PropertyGridView.FooterRow.FindControl("PriceTextBox
")).Text);

Any clue why this is happening?



Stack Trace:

[NullReferenceException: Object reference not set to an instance of an
object.]
AllProperies.PropertyGridView_RowCommand(Object sender,
GridViewCommandEventArgs e) in c:\Documents and Settings\Flynn\My
Documents\My Webs\CVM Web Portal\AllProperies.aspx.cs:70
System.Web.UI.WebControls.GridView.OnRowCommand(GridViewCommandEventArgs
e) +75
System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean
causesValidation, String validationGroup) +76
System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source, EventArgs
e) +88
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source,
EventArgs e) +117
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +86
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String
eventArgument) +153
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.Rai
sePostBackEvent(String
eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +172
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4919
 
M

Microsoft News Group

Yea named the object wrong you are correct.

"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:%[email protected]...
Best guess is that FindControl is failing to find a control wth the id of
"PriceTextBox" so ur getting a null object back.

Of course, the other option is that PropertyGridView.FooterRow is null...

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/


Microsoft News Group said:
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.



decimal price =
decimal.Parse(((TextBox)PropertyGridView.FooterRow.FindControl("PriceTextBox")).Text);

Any clue why this is happening?



Stack Trace:

[NullReferenceException: Object reference not set to an instance of an
object.]
AllProperies.PropertyGridView_RowCommand(Object sender,
GridViewCommandEventArgs e) in c:\Documents and Settings\Flynn\My
Documents\My Webs\CVM Web Portal\AllProperies.aspx.cs:70

System.Web.UI.WebControls.GridView.OnRowCommand(GridViewCommandEventArgs
e) +75
System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean
causesValidation, String validationGroup) +76
System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source,
EventArgs e) +88
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
+35
System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source,
EventArgs e) +117
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
+35
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +86
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String
eventArgument) +153

System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
+172
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+4919
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,697
Latest member
AugustNabo

Latest Threads

Top