Messagebox linked to link button

T

tshad

I was looking at Scott Mitchells article:
http://aspnet.4guysfromrolla.com/articles/090402-1.2.aspx the tells how to
call a messagebox from a button and can almost get it to work but ran into 2
problems. You have to press the button twice to get it to work and I can't
figure out how to get an answer (OK or Cancel) from it.

Here is the onClick function:

sub Resume_Click(sender as Object, e as eventArgs)
btnResume.Attributes("onclick") = "javascript:return " & _
"confirm('Are you sure you want to delete FAQ #?')"
end sub

The linkbutton is:

Would you like to submit a <asp:LinkButton id="btnResume"
Text="Resume" onClick="Resume_Click" runat="server"/>&nbsp;?

What am I missing?

Thanks,

Tom
 
S

Steve C. Orr [MVP, MCSD]

Take the code out of the Resume_Click event and put it in the Page_Load
event.
 
R

Ryan Trudelle-Schwarz

I was looking at Scott Mitchells article:
http://aspnet.4guysfromrolla.com/articles/090402-1.2.aspx the tells
how to call a messagebox from a button and can almost get it to work
but ran into 2 problems. You have to press the button twice to get it
to work and I can't figure out how to get an answer (OK or Cancel)
from it.

Here is the onClick function:

sub Resume_Click(sender as Object, e as eventArgs)
btnResume.Attributes("onclick") = "javascript:return " & _
"confirm('Are you sure you want to delete FAQ #?')"
end sub
The linkbutton is:

Would you like to submit a <asp:LinkButton id="btnResume"
Text="Resume" onClick="Resume_Click" runat="server"/>&nbsp;?

What am I missing?

Thanks,

Tom

What you want to do is set the onclick attribute in the load or pre render.
Then handle the click action in the Resume_Click method (ie, in this case,
looks like you want to delete a faq entry, do it there).
 
T

tshad

Ryan Trudelle-Schwarz said:
What you want to do is set the onclick attribute in the load or pre
render. Then handle the click action in the Resume_Click method (ie, in
this case, looks like you want to delete a faq entry, do it there).

It works now.

I understand what Scott was doing now. You have to set it before the
routine is called. In my case, I was setting it in the routine I was
calling.

Actually, I wasn't deleting an faq entry, just using the button Scott set
up, just to get it to work.

Thanks,

Tom
 

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,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top