Solved

Messagebox woth confirm options

Posted on 2007-11-23
8
598 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP.net Have sliders change in order 2 22
Show/Hide ASP.NET controls with JQuery best practices 3 46
asp day pilot 3 18
Modal Popup Extender control 1 18
I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

786 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