Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2185
  • Last Modified:

Yes / No Confirmation Box for ASP.NET Web Pages?

Yes / No Confirmation Box for ASP.NET Web Pages?

Hi Experts,

I’ve been spending a few hours looking for a Javascript equivalent of a Yes / No confirmation box solution (much like the link below), to no avail.
http://www.w3schools.com/js/tryit.asp?filename=tryjs_confirm

Apparently, most of the solutions I’ve found only works in Web Forms. Some of them utilize a postback solution, which isn’t for Web Pages.  

So I was wondering if there was a quick and easy Web Pages solution?

Thanks!
0
nvs_victor
Asked:
nvs_victor
  • 3
  • 3
  • 2
3 Solutions
 
mathew_sCommented:
You can use the following javascript library. Refer to it in your page.
http://dev.sencha.com/deploy/ext-4.0.0/examples/message-box/msg-box.js

Check this link out that uses the library.
http://dev.sencha.com/deploy/ext-4.0.0/examples/message-box/msg-box.html
The first is yes/no javascript dialog using the library.
0
 
Julian HansenCommented:
Here is some sample code that demonstrates the principle
<!doctype html>
<html>
<head>
<title>Test</title>
<script src="http://code.jquery.com/jquery.js"></script>
<script type="text/javascript">
$(function() {
    // Catch the open click
    $('a.popup').click(function(e){
	    // prevent <a> from doing its usual thing and browsing away from page.
        e.preventDefault();
		// What popup do we want to show (can support more than one this way)
        var id = $(this).attr('href');
		// Work out where to put it - left is half the width of the doc less half the width of the popup
        var left = ($(document).width() - $(id).width()) >> 1;
		// Same with top - use the >> to divide by 2 because old school
        var top = ($(document).height() - $(id).height()) >> 1;
		// create a clone of our template, show it set the metrics to position it add a class to show it is on screen and remove the id so we don't have dupes
        var popup = $(id).clone().show().css({left: left + 'px', top: top + 'px'}).addClass('popped').attr('id','');
		// create an overlay to make our popup modal
        var overlay = $('<div/>').addClass('overlay').css({height: $(document).height() + 'px'});
		
		// finally add to the body
        $('body').prepend(overlay).append(popup);
    });
    
	// Dynamic click handler for close button -  remove the layers we created in open
    $('body').on('click','.close', function(e) {
        e.preventDefault();
        $('.overlay').remove();
        $('.popped').remove();
    });
});
</script>
<style type="text/css">
.overlay {
    position: absolute;
    left: 0;
    top: 0;
    background: #000;
    opacity: .95;
    z-index: 1;
    width: 100%;
}
.popup-box {
    position: absolute;
    z-index: 100;
    display: none;
}
#popup {
    width: 300px;
    height: 150px;
    border: 2px solid #ef092a;
    background: #fff;
}
</style>
</head>
<body>
<a href="#popup" class="popup">Click to open popup</a>
<div id="popup" class="popup-box" >
Put what you want in here
<a href="#" class="close">This link closes the popup</a>
</div>    
</body>
</html>

Open in new window

0
 
mathew_sCommented:
In the case I have above, you will need to purchase the Sencha Ext JS framework I believe but can do a lot of cool things with it.
http://www.sencha.com/products/extjs/examples/

If you want to just write some code, the following will not give you a yes/no but an OK, cancel and it is javascript.

<html>
<head>
<script type="text/javascript">
<!--
function confirmation() {
	var answer = confirm("OK to leave site?")
	if (answer){
		alert("Bye bye!")
		window.location = "http://www.google.com/";
	}
	else{
		alert("Thanks for sticking around!")
	}
}
//-->
</script>
</head>
<body>
<form>
<input type="button" onclick="confirmation()" value="Click here">
</form>
</body>
</html>

Open in new window

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!

 
nvs_victorAuthor Commented:
Hi mathew_s and julianH,

thank you for helping!

Unfortunately, this won't help... Javascript is client-side... ASP.NET is server side. If I were to use Javascript to capture the what the user pressed, I'll need to capture the input and send it to ASP to process it. Javascript cannot help.

If I'm not mistaken, this is the process:

HTML Request -->  Server --> ASP Processing --> create HTML page with Javascript inside --> Sends HTML page to original requester.

As you can see, Javascript is at the end of the processing list... it's one direction only.  Sure, I can prompt the user with Javascript, but Javascript cannot tell ASP what button the client pressed.

The only solution with Javascript is if I send the input back to the server, but that's complicated.
0
 
Julian HansenCommented:
And the alternative is ....?

You can't do it in ASP.

If you need to send something back to the server you will need to AJAX it.

Using JQuery you would use the .ajax or .post function to call a server side script with the result of the user request.

Unless I missed the point of your question entirely what you are wanting to do - process the input entirely with ASP is not possible. ASP completes its processing before the browser displays anything to the user - it then goes away and is not invoked again until another call to a script is made.

Am I understanding you correctly?
0
 
nvs_victorAuthor Commented:
Hi  julianH,

So yes, you understood my question completely. And you clarified something I was missing.

"process the input entirely with ASP is not possible. ASP completes its processing before the browser displays anything to the user - it then goes away and is not invoked again until another call to a script is made."

Yes, same reason as why Javascript can't be used.

"Using JQuery you would use the .ajax or .post function to call a server side script with the result of the user request."
Sounds like a good alternative.

However, I found a simple method:
Thanks to your clarification, I found that I can use Javascript and display a confirmation box, and based on the response,  do a page re-direct to the same page, and pass values into the URL, and that way, I can handle the input in ASP. Works very well… thank God for a good workaround : )

Also, I apologize for my question being ambiguous and misleading; I see how I could have worded better.

Thanks guys and thanks julianH!
0
 
Julian HansenCommented:
You are welcome - thanks for the points.
0
 
nvs_victorAuthor Commented:
Experts helped me think of a workable solution using javascript.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now