Solved

Messagebox woth confirm options

Posted on 2007-11-23
8
602 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 125 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

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 50 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 200 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 200 total points
ID: 20358229
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

688 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