Link to home
Start Free TrialLog in
Avatar of nvs_victor
nvs_victorFlag for United States of America

asked on

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!
Avatar of mathew_s
mathew_s

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.
Avatar of Julian Hansen
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

SOLUTION
Avatar of mathew_s
mathew_s

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nvs_victor

ASKER

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.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You are welcome - thanks for the points.
Experts helped me think of a workable solution using javascript.