Solved

javascript confirm in c# code behind

Posted on 2009-07-06
6
1,942 Views
Last Modified: 2012-06-21
Trying to figure out how to determine if the user hit 'OK' or 'Cancel' from the javascript confirm in code behind.

If the user hits 'OK' it needs to call another method else just return to the page.
ClientScript.RegisterStartupScript(this.GetType(), "Orders", "<script>confirm(" + strConfirmMessage + ")</script>");
        return;

Open in new window

0
Comment
Question by:chris_desborough
[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
6 Comments
 
LVL 20

Accepted Solution

by:
informaniac earned 125 total points
ID: 24791671
Try using the vbscript MessageBox. It will give u a yes / no button which u could track.
0
 
LVL 23

Expert Comment

by:Saqib Khan
ID: 24791687
ClientScript.RegisterStartupScript(this.GetType(), "Orders", "<script>msg=confirm(" + strConfirmMessage + ");if(msg){alert('ok was clicked')}</script>");
0
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 24791747
as far as i understand the postback will happen only if the user select ok in the confirm box
if the user clicks cancel then nothing will happen and the control will remian on the page itself
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 9

Expert Comment

by:Deathrace
ID: 24792405
May be this helps
use the two events , onClientclick and onClick, onClick event will be triggered once the onClientclick event returns true.
So use a javascript funtion which pops a message box on client side and if that funtion returns true it will trigger the onclick event.
0
 
LVL 9

Expert Comment

by:Rahul Goel ITIL
ID: 24792450
ClientScript.RegisterStartupScript(this.GetType(), "Orders", "<script>msg=confirm(" + strConfirmMessage + ");if(msg){ __dopostback(this, "okParameter");}else{__dopostback(this, "CancelParameter");}(</script>"); return;
0
 
LVL 1

Author Comment

by:chris_desborough
ID: 24799784
Hi Rahu,

I had to use single quotes instead on okParameter and CancelParameter otherwise works ok. When the javascript is executed I get an error "Object expected". Debug says that __dopostback is not defined. Method in code snippet.
protected void LinkButton1_Click(object sender, EventArgs e)
    {
 
        strConfirmMessage = @"ORDER SUMMARY: Please review the items in your order\n\n";
 
        if (dt.Rows.Count > 0)
        {
 
            foreach (DataRow row in dt.Rows)
            {
 
                strConfirmMessage = @strConfirmMessage + (string)row["Desc"] + @"\n\n";
 
            }
 
 
            strConfirmMessage = @strConfirmMessage +
        @"\nClick OK to place your order or Cancel to continue modify your order.".ToString();
 
        ClientScript.RegisterStartupScript(this.GetType(), "Orders", "<script>msg=confirm('" + strConfirmMessage + "');if(msg){ __dopostback(this, 'okParameter');}else{__dopostback(this, 'CancelParameter');}</script>"); return; 
        
        }
 
 
        else
        {
            Response.Write("<script>alert('Unable to checkout - there are no items in the order.')</script>");
            return;
 
        }

Open in new window

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

636 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