Home All Groups Group Topic Archive Search About

Object reference not set to an instance of an object.

Author
15 Nov 2006 1:49 PM
Kiran More
WebControl button = (WebControl)Page.FindControl("btn_Delete");

button.Attributes.Add("onclick", "return confirmDelete (this.form);");

confirmDelete is the method written in Javascript.


I am getting following error message as,

Object reference not set to an instance of an object.

Author
15 Nov 2006 7:58 PM
Yvonne
Hy Kiran,
Are you sure that this control exists on the page? FindControl returns
a null reference if it doesn't find the control. This seems to be your
problem, that is the caus of your exception.
Yvonne

Kiran schrieb:

Show quoteHide quote
> WebControl button = (WebControl)Page.FindControl("btn_Delete");
>
> button.Attributes.Add("onclick", "return confirmDelete (this.form);");
>
> confirmDelete is the method written in Javascript.
>
>
> I am getting following error message as,
>
> Object reference not set to an instance of an object.
Author
16 Nov 2006 3:24 AM
MikeS
Maybe just set the OnClientClick property of the button instead of
going to the trouble of trying to find it.