Solved

Messagebox woth confirm options

Posted on 2007-11-23
8
596 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Automatic sizing of HTML.TextAreaFor based on content 1 26
Not showing page correctly 3 31
Data is not showing from images 15 38
SQL Exceptions 3 39
AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

867 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

22 Experts available now in Live!

Get 1:1 Help Now