Wednesday, March 21, 2012

Object reference not set to an instance of an object.

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(Gr idViewCommandEventArgs
e) +75
System.Web.UI.WebControls.GridView.HandleEvent(Eve ntArgs e, Boolean
causesValidation, String validationGroup) +76
System.Web.UI.WebControls.GridView.OnBubbleEvent(O bject source, EventArgs
e) +88
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
System.Web.UI.WebControls.GridViewRow.OnBubbleEven t(Object source,
EventArgs e) +117
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
System.Web.UI.WebControls.LinkButton.OnCommand(Com mandEventArgs e) +86
System.Web.UI.WebControls.LinkButton.RaisePostBack Event(String
eventArgument) +153
System.Web.UI.WebControls.LinkButton.System.Web.UI .IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +172
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4919Best 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" <mflynn@.cvmediaonline.comwrote in message
news:OLgUH6%23uGHA.4472@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

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(Gr idViewCommandEventArgs
e) +75
System.Web.UI.WebControls.GridView.HandleEvent(Eve ntArgs e, Boolean
causesValidation, String validationGroup) +76
System.Web.UI.WebControls.GridView.OnBubbleEvent(O bject source,
EventArgs e) +88
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
+35
System.Web.UI.WebControls.GridViewRow.OnBubbleEven t(Object source,
EventArgs e) +117
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
+35
System.Web.UI.WebControls.LinkButton.OnCommand(Com mandEventArgs e) +86
System.Web.UI.WebControls.LinkButton.RaisePostBack Event(String
eventArgument) +153
>
System.Web.UI.WebControls.LinkButton.System.Web.UI .IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +172
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4919
>
>
>
>


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 =

Quote:

Originally Posted by

>


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

"Microsoft News Group" <mflynn@.cvmediaonline.comwrote in message
news:OLgUH6%23uGHA.4472@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

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);

Quote:

Originally Posted by

>
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(Gr idViewCommandEventArgs

Quote:

Originally Posted by

e) +75
System.Web.UI.WebControls.GridView.HandleEvent(Eve ntArgs e, Boolean
causesValidation, String validationGroup) +76
System.Web.UI.WebControls.GridView.OnBubbleEvent(O bject source,


EventArgs

Quote:

Originally Posted by

e) +88
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)


+35

Quote:

Originally Posted by

System.Web.UI.WebControls.GridViewRow.OnBubbleEven t(Object source,
EventArgs e) +117
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)


+35

Quote:

Originally Posted by

System.Web.UI.WebControls.LinkButton.OnCommand(Com mandEventArgs e) +86
System.Web.UI.WebControls.LinkButton.RaisePostBack Event(String
eventArgument) +153
>


System.Web.UI.WebControls.LinkButton.System.Web.UI .IPostBackEventHandler.Rai
sePostBackEvent(String

Quote:

Originally Posted by

eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)


+172

Quote:

Originally Posted by

System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4919
>
>
>
>


Yea named the object wrong you are correct.

"Karl Seguin [MVP]" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME
netwrote in message news:%23nXsqL$uGHA.4612@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

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" <mflynn@.cvmediaonline.comwrote in message
news:OLgUH6%23uGHA.4472@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

>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(Gr idViewCommandEventArgs
>e) +75
> System.Web.UI.WebControls.GridView.HandleEvent(Eve ntArgs e, Boolean
>causesValidation, String validationGroup) +76
> System.Web.UI.WebControls.GridView.OnBubbleEvent(O bject source,
>EventArgs e) +88
> System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
>+35
> System.Web.UI.WebControls.GridViewRow.OnBubbleEven t(Object source,
>EventArgs e) +117
> System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
>+35
> System.Web.UI.WebControls.LinkButton.OnCommand(Com mandEventArgs e) +86
> System.Web.UI.WebControls.LinkButton.RaisePostBack Event(String
>eventArgument) +153
>>
>System.Web.UI.WebControls.LinkButton.System.Web.UI .IPostBackEventHandler.RaisePostBackEvent(String
>eventArgument) +7
> System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
>sourceControl, String eventArgument) +11
> System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
>+172
> System.Web.UI.Page.ProcessRequestMain(Boolean
>includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
>+4919
>>
>>
>>
>>


>
>

0 comments:

Post a Comment