?
Solved

OKCancel Messagebox

Posted on 2004-09-23
12
Medium Priority
?
1,366 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 1200 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

762 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