Solved

OKCancel Messagebox

Posted on 2004-09-23
12
1,362 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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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
 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Exceptions 3 46
Checkbox in a dynamic GridVIew is not clickable? 5 27
Problem to refer to value 8 50
ASP.NET MVC identity 6 27
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

810 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