Solved

Messagebox woth confirm options

Posted on 2007-11-23
8
595 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
  • 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
 

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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now