vbscript msgbox confirmation when user clicks Cancel button

B

Bucky

I haven't found any vbscript code that can stop the form
submission/postback after the msgbox. The problem is that asp:button is
rendered as <input type="submit"> instead of <input type="button">. So
instead of doing a "document.form(0).submit" upon "Yes", I need to stop
the form submission upon "No". Javascript is easy since you can do
"return confirm...", but I'm looking for a vbscript solution.

Here's my relevant code:

<asp:button id="btnCancel" Text="Cancel" Runat="server"></asp:button>

btnCancel.Attributes.Add("onclick", "msgbox 'Are you sure you want to
cancel?', vbYesNo");
 
B

Bucky

I finally found the code. The key was setting window.event.returnValue.

function confirm()
retval = msgbox("Are you sure?", vbYesNo)
if retval = vbYes then
window.event.returnValue = true
else
window.event.returnValue = false
end if
end function

<asp:button id="btnCancel" Text="Cancel" Runat="server"></asp:button>

btnCancel.Attributes.Add("oncl­ick", "vbscript: confirm()");
 

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,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top