[转]jQuery UI Dialog Modal Popup Yes No Confirm example in ASP.Net

本文转自:http://www.aspsnippets.com/Articles/jQuery-UI-Dialog-Modal-Popup-Yes-No-Confirm-example-in-ASPNet.aspx

In this article I will explain with an example, how to use jQuery UI Dialog Modal Popup as Yes No Confirmation Box in ASP.Net using C# and VB.Net.
The jQuery UI Dialog Modal Popup can be configured to work as the JavaScript Yes No Confirmation Box by using Custom Buttons.
 
 
HTML Markup
The following HTML Markup consists of jQuery UI Script and CSS files inherited to use jQuery UI Dialog Modal Popup box, an HTML DIV and an ASP.Net Button with UseSubmitBehavior property set to False.
Inside the  jQuery document ready event handler, the jQuery UI Dialog Modal Popup box is initialized and the Delete Button is assigned the jQuery click event handler.
 
In this scenario the jQuery UI Dialog Modal Popup box makes of Custom Buttons, to read more about it please refer my article  jQuery UI Dialog Modal Popup Custom Buttons example .
The  jQuery UI Dialog Modal Popup bo x has two Custom Buttons i.e. Yes and No. When the Yes Button is clicked, the rel attribute of the Delete button is set to value delete and the click event of the Delete Button is triggered.
And when the No Button is clicked, the jQuery UI Dialog Modal Popup box is closed using the “close” command.
When the Button is clicked, if the  rel attribute does not have value  delete, the jQuery UI Dialog Modal Popup box is opened using the “open” command, else using the __doPostBack function, the Sever Side event handler of the Button is triggered.
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/jquery-ui.js" type="text/javascript"></script>
<link href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/themes/blitzer/jquery-ui.css"
    rel="stylesheet" type="text/css" />
<script type="text/javascript">
    $(function () {
        $("[id*=btnDelete]").removeAttr("onclick");
        $("#dialog").dialog({
            modal: true,
            autoOpen: false,
            title: "Confirmation",
            width: 350,
            height: 160,
            buttons: [
            {
                id: "Yes",
                text: "Yes",
                click: function () {
                    $("[id*=btnDelete]").attr("rel", "delete");
                    $("[id*=btnDelete]").click();
                }
            },
            {
                id: "No",
                text: "No",
                click: function () {
                    $(this).dialog('close');
                }
            }
            ]
        });
        $("[id*=btnDelete]").click(function () {
            if ($(this).attr("rel") != "delete") {
                $('#dialog').dialog('open');
                return false;
            } else {
                __doPostBack(this.name, '');
            }
        });
    });
</script>
<asp:Button ID="btnDelete" runat="server" Text="Delete" OnClick="DeleteRecord" UseSubmitBehavior="false" />
<div id="dialog" style="display: none" align="center">
    Do you want to delete this record?
</div>
 
 
Server Side Code
When the Yes option is clicked inside the jQuery UI Dialog Modal Popup box, the following event handler is raised which simulates deletion of record.
C#
protected void DeleteRecord(object sender, EventArgs e)
{
    ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Record Deleted.')", true);
}
 
VB.Net
Protected Sub DeleteRecord(sender As Object, e As EventArgs)
    ClientScript.RegisterStartupScript(Me.GetType(), "alert", "alert('Record Deleted.')", True)
End Sub
 
 
Screenshot
 
 
Browser Compatibility

The above code has been tested in the following browsers. 

转载于:https://www.cnblogs.com/freeliver54/p/5139471.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值