Solved

OKCancel Messagebox

Posted on 2004-09-23
12
1,360 Views
Last Modified: 2010-05-18
Hello,
I know that you cannot use MessageBox.show() in asp.net and use the following code to bring up a simple alert messagebox:
System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE=JavaScript> alert(""Blah"") </SCRIPT>")

I have changed the word 'alert' into 'confirm' and brought up an ok/cancel box (as required) however do not know how to capture the ok or cancel as clicking either button does the same thing.

Can you please tell me how to differentiate between the ok and cancel button being clicked so i can perform the desired event (if ok is clicked) or not (if cancel button is clicked)

Thanks in advance,
Max
0
Comment
Question by:mcgants
  • 4
  • 4
  • 2
  • +2
12 Comments
 
LVL 17

Assisted Solution

by:AerosSaga
AerosSaga earned 300 total points
Comment Utility
function confirmSubmit() {
var doc = document.forms[0];
var msg = "Are you sure you want to submit this data?";
if (confirm(msg)) {
doc.submit();
} else {
// do nothing
} }

<input type=”button” value=”submit” name=”butSubmit” onClick=”confirmSubmit();”>

butSubmit.Attributes.Add("onClick", "return confirmSubmit();")

Use this one, if you hit confirm then it posts, if not it doesn't

Regards,

Aeros
0
 
LVL 6

Author Comment

by:mcgants
Comment Utility
thanks for your fast answer, any chance you might have it in vb/asp.net? am having a few problems converting over. also is document.forms a generic term or do i have to add in a different term?

thanks again,
Max
0
 
LVL 17

Expert Comment

by:AerosSaga
Comment Utility
its genric , and that is vb/asp.net it just uses a plain html submit
0
 
LVL 6

Author Comment

by:mcgants
Comment Utility
surely the function is written in c#? you've used semicolons
0
 
LVL 17

Expert Comment

by:AerosSaga
Comment Utility
thats javascript my friend
0
 
LVL 17

Expert Comment

by:AerosSaga
Comment Utility
It has to be client side to display the message and thus your only option for this is javascript.
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 6

Author Comment

by:mcgants
Comment Utility
my apologies, late in the day here :p
finally, is there anything i can do to make this work with an asp button instead of a html one?
when i run my program it creates a compiler error that confirmSubmit is not a member of the class. boo!
0
 
LVL 15

Expert Comment

by:praneetha
Comment Utility
<asp:Button id="btnSave" runat="server" Width="120px" Text="Save"></asp:Button>

in Page_Load
{
btnSave.Attributes.Add("onClick", "return confirmSubmit();")
}

if returns false...that is if user clicks cancel...

the btnSave_click will never fire...

if they say ok the btnSave_click fires...

good luck
0
 
LVL 6

Author Comment

by:mcgants
Comment Utility
i am trying that but it fires whether ok or cancel are clicked(!!)
any help is most appreciated, but i will be back in the morning to try more. thanks both, if u can help me get this working i will be v.thankful :)
good nite,
Max
0
 
LVL 15

Accepted Solution

by:
praneetha earned 200 total points
Comment Utility
ok change the javascript function to

function confirmsubmit()
            {
            if (confirm("Are you sure you want to submit?")==true)
            return true;
            else
            return false;
            }

it should work fine now
0
 
LVL 18

Expert Comment

by:tusharashah
Comment Utility
Same thing, different approch:

Just add following line in your Page_Load
--------------------------------------------------------------------------------------------------------
Button1.Attributes.Add("OnClick", "return confirm('Are you sure?');");
--------------------------------------------------------------------------------------------------------

-tushar
0
 
LVL 18

Expert Comment

by:DotNetLover_Baan
Comment Utility
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now