开发者

Modal Confirm Box Using JQuery in ASP.Net

I want a similar behavior of “confirm delete” option in ASP.Net Gridview, as this questions shows How to add a "confirm delete" option in ASP.Net Gridview? but using Jquery Confirm Box.

I'm having a lot of problem with postback behavior and asp.net page flow.

I want domething simple as:

<asp:Button ID="ButtonRemove" runat="server" Text="<%$ Resources:Localizacao, BUTTON_REMOVE %>" OnClick="ButtonRemove_Click" OnClientC开发者_JAVA技巧lick="displayConfirmDialog();/>

Some idea how I can fire the OnClick event in javascript, or how a can put a Panel as confirm dialog?

*today I use ajaxcontroltoolkit, but as this was discontinued I'm trying to figure out some more elegant alternative.


1 - have a hidden div that is going to be your dialog box. Put this at the bottom of your HTML, outside your main page markup.

<div id="dialog1" class="dialog" style="display:none">
   SOME TEXT
   <a href="javascript://" onclick="confirmDialog()">CONFIRM</a>
</div>

Style it like so:

.dialog {
   position:absolute;
   width:250px;
   height:250px;
   background-color:#ffffff
}

.dialog a {
    display:block;
    padding:5px;
    margin-top:50px;
    background-color:#c0c0c0
}

2 - Center the dialog before showing it:

centerMe('#dialog1')

function centerMe(element) {
    //pass element name to be centered on screen
    var pWidth = jQuery(window).width();
    var pTop = jQuery(window).scrollTop()
    var eWidth = jQuery(element).width()
    var height = jQuery(element).height()
    jQuery(element).css('top', pTop + 100 + 'px')
    jQuery(element).css('left', parseInt((pWidth / 2) - (eWidth / 2)) + 'px')
}

3 - show the dialog:

jQuery('#dialog1').fadeIn('slow')

4 - create a function to handle the CONFIRM button:

function confirmDialog() {
    jQuery('#dialog1').hide()
    ... your code ...
}

If you want to get fancy you can create a background image for the dialog instead of a simple white background.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜