object reference not set to an instance of an object

G

Guest

hi there,

I looked up posts on how to get a javascript confirm on the onclick of a
button to determine whether to run server code and i wrote this on the page
load..

string jsalert = "javascript:if(confirm ('Is the employee a rehire?') ==
false) return false";
btnEdit.Attributes["onclick"]=jsalert;

however I'm getting the error message in my subject heading. what have i
done wrong? when i start to write it i get intellisense so i know it
recognises btnEdit.
 
K

Ken Dopierala Jr.

Hi,

Make sure in your HTML that your id tag is exactly "btnEdit" with the
correct case. You receive it in intellisense because it is declared in your
code behind which doesn't necessarily mean it is in your .aspx file. Good
luck! Ken.
 
K

Kevin Spencer

Try the following:

btnEdit.Attributes.Add("onclick", jsalert);

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.
 
G

Guest

hiya. yes. its as btnEdit in both my aspx, my declarations and my code ???

Ken Dopierala Jr. said:
Hi,

Make sure in your HTML that your id tag is exactly "btnEdit" with the
correct case. You receive it in intellisense because it is declared in your
code behind which doesn't necessarily mean it is in your .aspx file. Good
luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

louise raisbeck said:
hi there,

I looked up posts on how to get a javascript confirm on the onclick of a
button to determine whether to run server code and i wrote this on the page
load..

string jsalert = "javascript:if(confirm ('Is the employee a rehire?') ==
false) return false";
btnEdit.Attributes["onclick"]=jsalert;

however I'm getting the error message in my subject heading. what have i
done wrong? when i start to write it i get intellisense so i know it
recognises btnEdit.
 
G

Guest

yes i did actually try that syntax. same error message:

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

Ken Dopierala Jr.

Hi,

Do you have the runat="server" tag in your btnEdit? Also, where and when
are you getting the error? Are you sure it happens on the
btnEdit.Attributes line? Also I would definitely switch your syntax to what
Kevin showed, that's how I've always done it. Try commenting out the
attributes line and do something else with the button. Like btnEdit.Visible
= True, if this gives you the same error then there is a problem with either
your button tag or your button declaration, if no error then we have
narrowed it down to how you are adding your attribute. Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

louise raisbeck said:
yes i did actually try that syntax. same error message:

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

louise raisbeck said:
hi there,

I looked up posts on how to get a javascript confirm on the onclick of a
button to determine whether to run server code and i wrote this on the page
load..

string jsalert = "javascript:if(confirm ('Is the employee a rehire?') ==
false) return false";
btnEdit.Attributes["onclick"]=jsalert;

however I'm getting the error message in my subject heading. what have i
done wrong? when i start to write it i get intellisense so i know it
recognises btnEdit.
 
K

Kevin Spencer

Well, Louise, you have 2 possibilities:

btnEdit is Null;
btnEdit.Attributes is null;

What exactly IS "btnEdit?"
--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

louise raisbeck said:
yes i did actually try that syntax. same error message:

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

louise raisbeck said:
hi there,

I looked up posts on how to get a javascript confirm on the onclick of a
button to determine whether to run server code and i wrote this on the page
load..

string jsalert = "javascript:if(confirm ('Is the employee a rehire?') ==
false) return false";
btnEdit.Attributes["onclick"]=jsalert;

however I'm getting the error message in my subject heading. what have i
done wrong? when i start to write it i get intellisense so i know it
recognises btnEdit.
 

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
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top