?
Solved

Messagebox woth confirm options

Posted on 2007-11-23
8
Medium Priority
?
606 Views
Last Modified: 2008-02-01
Greetings

I am in need of a message box (for an ASP.Net app) that allows the the user to choose from one or two options. After allowing the user to select, the application must be able to detect what button was clicked and execute appropriate coding.

Any ideas?


allanmark
0
Comment
Question by:allanmark
[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
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 7

Expert Comment

by:nisarkhan
ID: 20340992
<html><head><title>href confirm</title>
<script type="text/javascript">
function linkRef(yurl ){
var linkref = yurl;
if(confirm("do you really want to go here?")){
window.location.href=linkref;
}
}
</script>
</head>
<body>
<a href="#" onClick="linkRef('http://www.yahoo.com' )">Yahoo.com</a>
</body>
</html>
0
 
LVL 7

Expert Comment

by:nisarkhan
ID: 20340997
or

using the default JavaScript confirm dialog you are stuck with "OK" and "Cancel"

The easiest way to do what you want is to call a function.

Button1.Attributes.Add("onClick", "myFunction();")

And then create your function on your page...

HTML Code:
<script type="text/javascript">
function myFunction() {
  if confirm('Do you want to mark this form as complete?\nThis is line 2.') {
    //put the stuff to do for OK here
  }
  else {
    //Put the stuff for Cancel here
  }
}
</script>To get a line break you can use the \n escape character. (Also in the example above.)
0
 
LVL 7

Accepted Solution

by:
nisarkhan earned 375 total points
ID: 20341011
are a number of ways you can do this. I'll give you a few options.

1. Use the ASP.NET AJAX ModalPopup Control from the AJAX Control Toolkit.

http://asp.net/AJAX/AjaxControlToolkit/Samples/ModalPopup/ModalPopup.aspx 

 2. Use Javascript.


<head runat="server">    
<title>Untitled Page</title>    
<script language="javascript" type="text/javascript">        
function confirmation()      
 {          
 var result = confirm('Record already exists, Do you really want to add?');          
 if (result)          
 {              
 return true;            
}            
else            
{                
return false;            
}        
}    
</script>
</head>

Then in your code-behind file add the following:
Button1.Attributes.Add("onclick", "return confirmation();");

0
Technology Partners: 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!

 

Author Comment

by:allanmark
ID: 20343515
What if you don't want to launch the messagebox from a button click? ie you want to call it from behind code (eg when the total num records exceeds a limit) - and you wanttoi eb able to store the value of the button clicked??

0
 
LVL 63

Assisted Solution

by:Zvonko
Zvonko earned 150 total points
ID: 20344371
You cannot interact from code behind to browser user. The HypertTextTransferProtocol allows you to send to one browser request only one web server reponse. Outside that request-response calls you cannot do anything, not even with AJAX. You cannot send NOTHING from server to browser outside that request-response calls. You cannot send not even two or more responses to one request, onely one reposnse to one request.

Also the web server execution has to finish it processing to flush the browser text response. So you cannot stop in the middle of your server processing to wait for browser response.



0
 
LVL 5

Assisted Solution

by:rajups
rajups earned 600 total points
ID: 20349461
Hi,
You can use the "RegisterStartupScript" to call the Java Script function from the code behind which will inturn do the required validation.

All the Best,
Raju P. S
0
 

Author Comment

by:allanmark
ID: 20353188
Tried the following:

    protected void Page_Load(object sender, EventArgs e)
    {
        string jScriptValidator;
        jScriptValidator = "<script> function ReqFieldValidator()" +
                    " { if (document.forms[0].TextBox1.value == '') \n";
        jScriptValidator += "{ alert('TextBox cannot be empty') \n ";
        jScriptValidator += "return false; \n";
        jScriptValidator += "} \n";
        jScriptValidator += " return true \n";
        jScriptValidator += " } </script>";
//        ClientScript.RegisterClientScriptBlock(GetType(), "regJSval", jScriptValidator);  
        ClientScript.RegisterStartupScript(GetType(), "regJSval", jScriptValidator);       //
        Button1.Attributes.Add("onclick", "return ReqFieldValidator()");        
    }

In the code above the JS function is attached to the button click event -- thsi works fine. I tried the RegisterCLeintScriptBlock --. thought it would execute the function immediately!! WHAT DID I DO WRONG??
0
 
LVL 5

Assisted Solution

by:rajups
rajups earned 600 total points
ID: 20358229
0

Featured Post

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.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

764 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