Solved

OKCancel Messagebox

Posted on 2004-09-23
12
1,364 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

697 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