【问题标题】:Disabling background or all controls on a ASPX page using Jquery使用 Jquery 禁用 ASPX 页面上的背景或所有控件
【发布时间】:2012-05-04 11:00:37
【问题描述】:

我正在使用此代码显示一个对话框,该对话框将确认删除按钮,它工作正常,但是当它弹出时它不会禁用 ASP.Net 页面的任何控件,因此我可以单击任何控件或文本框,

我想做的第一件事是在 Jquery 打开我的 Div 标签框时淡出页面,然后禁用所有控件。

这是代码

Div(自定义对话框)

    <div id="divConfMessage">
        <div align="center">
            <br /><asp:Label ID="Label1"  runat="server" Text="Deleting this eDecision will remove all site content and uploaded documents. Are you sure you wish to continue?" CssClass="headertext"></asp:Label><br /><br /><br /><br /><br />
            <asp:Button ID="btnConfOK" Width="200px" Height="25px" CssClass="gradientbutton" OnClick="btDelete_Click" Runat="server" Text="Yes"></asp:Button>
            <asp:Button ID="btnConfCancel" Width="200px" Height="25px" CssClass="gradientbutton" Runat="server" Text="No"></asp:Button><br /><br /><br />
        </div>
</div>

脚本 (jquery)

    <script type="text/javascript" src="/_layouts/1033/jquery.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $("input[id$='btDelete']").click(function() 
        {
        $("#divConfMessage").fadeIn();
        });
    });
</script>

按钮

    <td>
    <asp:Button ID="btDelete" runat="server" CssClass="gradientbutton" OnClick="btDelete_Click"
    OnClientClick="this.disabled=true;this.value='Please Wait...';" Text="Delete" Width="200px"  />
</td>

对话框的 CSS

    #divConfMessage
{
    position: absolute;
    width: 500px;
    height: 200px;
    top: 50%;
    left: 30%;
    margin-left: -150px; /* Negative half of width. */
    margin-top: -100px; /* Negative half of height. */
    border: 2px solid #000;
    DISPLAY:none;
    background-color:White;
    line-height:20px;
    text-align:center;
}

注意

所有代码都在页面的 ASP 内容占位符中,除了 CSS,我还有 2 个具有不同控件的内容 + 一个定义所有这些内容占位符的母版页。

<asp:Content ID="Content4" ContentPlaceHolderID="cphSubmit" runat="server">
<%@ Page Language="C#" MasterPageFile="~/my.Master" AutoEventWireup="true" CodeBehind="c.aspx.cs" Inherits="a.b.c" Title="e"  meta:resourcekey="PageResource1"  %>

【问题讨论】:

    标签: c# javascript jquery asp.net dialog


    【解决方案1】:

    设置模态=true;对于 dilogbox 有 modal 属性,可以设置为 True。

    尝试使用Jquery dialogue box(它带有 JqueryUI 插件)。

    $( "#YourDivorContainerToShowAsDialog" ).dialog({
                modal: true,
                buttons: {
                    Ok: function() {
                        $( this ).dialog( "close" );
                    }
                }
            });
    

    编辑:如果你不想使用按钮,那么就这样使用

      $( "#YourDivorContainerToShowAsDialog" ).dialog({
                    modal: true             
                });
    

    或者如果你想使用CSS,那么你可以尝试

    #YourDivorContainerToShowAsDialog 
    {
    position: absolute;
    Z-index: withMaxValue
    }
    

    【讨论】:

    • 嘿 Ravi,谢谢你的回答,我已经试过了,但是我的 Div 已经有一个 asp.net 按钮,所以不想使用对话框按钮 + 它变得非常混乱
    • @TimeToThine 你可以忽略按钮。只使用模态属性。这样你的 div 就会变成模态框
    • 感谢伙伴,我试过了,但它仍然没有禁用任何东西:|
    【解决方案2】:

    #divConfMessage 提供更高的Z-index,然后模态dalog 将位于所有内容之上。

    当您添加对话框时,以这种方式将其附加到正文:

     add_block_page();
     add_modal_box();
    
    
    
    function add_block_page(){
        var block_page = $('<div class="page"></div>');
        $(block_page).appendTo('body');
    }
    
    function add_modal_box(){
        var pop_up = $('<div id="divConfMessage"></div>');
         $(pop_up).appendTo('.page');
     }
    

    【讨论】:

    • 暂时它在一切之上,但只是不阻止它后面的页面:)
    • 改变背景颜色为白色
    • 如果我使用你的代码行,它会附加 Div 的主体,而不是页面:|
    【解决方案3】:

    使用一张透明图片淡出页面。

    添加一个outerDiv并将图像应用到该div。

    <div id="outerDiv"  style="display:none;">
    <div id="divConfMessage">
            <div align="center">
                <br /><asp:Label ID="Label1"  runat="server" Text="Deleting this eDecision will remove all site content and uploaded documents. Are you sure you wish to continue?" CssClass="headertext"></asp:Label><br /><br /><br /><br /><br />
                <asp:Button ID="btnConfOK" Width="200px" Height="25px" CssClass="gradientbutton" OnClick="btDelete_Click" Runat="server" Text="Yes"></asp:Button>
                <asp:Button ID="btnConfCancel" Width="200px" Height="25px" CssClass="gradientbutton" Runat="server" Text="No"></asp:Button><br /><br /><br />
            </div>
    </div>
    </div>
    

    outerDiv 的 CSS

    # outerDiv
    {
    top:0%;
    left:0%;
    position:absolute;
    background-image:url('../img/FloatingPanel.png');//transperant image
    color:White;
    z-index: 1102;
    Height:100%;
    width:100%;
    }
    

    为#divConfMessage 提供比outerDiv 的Z-index 更高的Z-index(即:1103)。 显示btDelete的outerDiv onclick

    【讨论】:

      猜你喜欢
      • 2011-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-28
      相关资源
      最近更新 更多