Solved

OKCancel Messagebox

Posted on 2004-09-23
12
1,361 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
ID: 12134381
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
ID: 12134542
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
ID: 12134580
its genric , and that is vb/asp.net it just uses a plain html submit
0
 
LVL 6

Author Comment

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

Expert Comment

by:AerosSaga
ID: 12134621
thats javascript my friend
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12134651
It has to be client side to display the message and thus your only option for this is javascript.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 6

Author Comment

by:mcgants
ID: 12134756
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
ID: 12135010
<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
ID: 12135083
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
ID: 12135167
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
ID: 12135739
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
ID: 12138756
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

948 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

22 Experts available now in Live!

Get 1:1 Help Now