简体   繁体   English

在 ASP.NET 中选中复选框时,如何显示弹出窗体?

[英]How can I show popup form when the checkbox is checked in ASP.NET?

I have a problem for showing popup form when the checkbox is already checked.当复选框已被选中时,我无法显示弹出表单。 I think I might need a script for this case.我想我可能需要一个脚本来处理这种情况。 Please help me to solve this.请帮我解决这个问题。

<asp:checkbox id="additem" class="additem" runat="server"/>
                                           
<asp:Content ID="Content3" ContentPlaceHolderID="chpPopUp" runat="server">
    <asp:Panel ID="pnlPopup" runat="server" Style="display: none;Width:80%;max-width:100%; ">
        <asp:Button Style="display: none" ID="btnShowPopup" runat="server"></asp:Button>
        <cc2:ModalPopupExtender ID="mdlPopup" runat="server" BehaviorID="mdlPopup" PopupControlID="pnlPopup"
            TargetControlID="btnShowPopup" BackgroundCssClass="modalBackground">
        </cc2:ModalPopupExtender>
        <cc2:DragPanelExtender ID="dpePopup" runat="server" TargetControlID="pnlPopup" DragHandleID="pnlPopupHeader" />
        <div class="modal-content" style="Width:80%;max-width:100%;">
            <asp:Panel ID="pnlPopupHeader" runat="server" BorderColor="Black">
                <div>
                    <!-- Modal content-->
                    <div class="modal-header">
                       ........
                    </div>
                </div>
            </asp:Panel>
            <asp:UpdatePanel ID="upnDetail" runat="server" UpdateMode="Conditional">
                <ContentTemplate>
                    <!-- class="modal-dialog"-->
                    <div>
                        <!-- Modal content-->
                        <div class="modal-body">

                </ContentTemplate>
            </asp:UpdatePanel>
        </div>
    </asp:Panel>
</asp:Content>

I tried using the following script but it didn't work.我尝试使用以下脚本,但没有用。

$('.additem').click(function () {
    var checked = $(this).is(':checked');
     if (checked) {
        document.getElementById("additem").value = "Yes";
       if (!confirm('Are you sure you want to mark this order as received?')) {
         $(this).removeAttr('checked');
         }
     }
     else {
     document.getElementById("additem").value = "No";
      if (!confirm('Are you sure you want to mark this order as  not received?')) {
         $(this).removeAttr('checked');
      }
     }
   });
<asp:checkbox id="additem" class="additem" runat="server"/>

should be put inside应该放在里面

<asp:Content ....></asp:Content>

and you could Press F12 to check how it was rendered when you debug, and you could try with return false to keep the statue of the checkbox, in my case, I tried as below:你可以按 F12 来检查调试时它是如何呈现的,你可以尝试使用return false来保持复选框的状态,在我的例子中,我试过如下:

<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<asp:checkbox ID="additem" class="additem" runat="server"/>

<script>
$('.additem').children("input[type='checkbox']").click(function () {
    var checked = $(this).is(':checked');
    if (checked) {
      
        if (!confirm('Are you sure you want to mark this order as received?')) {
            return false
        }
    }
    else {
       
        if (!confirm('Are you sure you want to mark this order as  not received?')) {
            return false
        }
    }
});
</script>

The result:结果:

在此处输入图像描述

The id/class attribute of the checkbox was not the same with what you set in the <asp:checkbox> tag.复选框的 id/class 属性与您在<asp:checkbox>标记中设置的不同。

After I modified the jQuery code, it works well:我修改了jQuery代码后,效果很好:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM