CSS / JS popup Modal马上关闭asp.net

时间:2017-11-07 16:22:42

标签: javascript html css asp.net

我有一个数据列表,我把它放在弹出式DIV之间,点击按钮后显示弹出窗口中的datalist结果。 它是作品并在弹出窗口显示结果但它立即关闭,我不知道为什么! 有人可以帮我解决问题。

我尝试使用“return false”它正在工作,但如果我想再次使用差异参数进行搜索,结果将不会更新。

这是我的HTML代码:         

    <style type="text/css">

        .modal {
    display: none; /* Hidden by default */
    position: fixed; /* Stay in place */
    z-index: 1; /* Sit on top */
    padding-top: 100px; /* Location of the box */
    left: 0;
    top: 0;
    width: 100%; /* Full width */
    height: 100%; /* Full height */
    overflow: auto; /* Enable scroll if needed */
    background-color: rgb(0,0,0); /* Fallback color */
    background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}

/* Modal Content */
.modal-content {
    position: relative;
    background-color: #fefefe;
    margin: auto;
    padding: 0;
    border: 1px solid #888;
    width: 80%;
    box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);
    -webkit-animation-name: animatetop;
    -webkit-animation-duration: 0.4s;
    animation-name: animatetop;
    animation-duration: 0.4s
}

/* Add Animation */
@-webkit-keyframes animatetop {
    from {top:-300px; opacity:0} 
    to {top:0; opacity:1}
}

@keyframes animatetop {
    from {top:-300px; opacity:0}
    to {top:0; opacity:1}
}

/* The Close Button */
.close {
    color: white;
    float: right;
    font-size: 28px;
    font-weight: bold;
}

.close:hover,
.close:focus {
    color: #000;
    text-decoration: none;
    cursor: pointer;
}

.modal-header {
    padding: 2px 16px;
    background-color: #5cb85c;
    color: white;
}

.modal-body {padding: 2px 16px;}

.modal-footer {
    padding: 2px 16px;
    background-color: #5cb85c;
    color: white;
}


        .auto-style1 {
            width: 59%;
            height: 150px;
        }
        .auto-style2 {
            width: 189px;
        }
        </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        .\\\some codes
        <br />
        <asp:Button id="myBtn" runat="server" OnClick="Button1_Click" Text="Button" value="Show Popup" />
        <br />
        <br />
        <br />
        <div id="myModal" class="modal">
          <div class="modal-content" >
    <div class="modal-header">
      <span class="close">&times;</span>
        <asp:DataList ID="DataList1" runat="server" >
            <ItemTemplate>
        <table class="auto-style1">
            <tr>
                <td class="auto-style2" rowspan="3"><asp:Image ID="imgEmp" runat="server" Width="250px" Height="150px" ImageUrl='<%# Bind("ImagesCar", "{0}") %>' style="padding-left:40px"/></td>
                <td colspan="5">
                    <b><u><%# Eval("NameC") %></td></u></b>
            </tr>
            <tr>
                <td>Tip</td>
                <td>GB</td>
                <td>Gh</td>
            </tr>
            <tr>
                <td><%# Eval("Tip")%></td>
                <td><%# Eval("GB")%></td>

                <td><%# Eval("Gh")%></td>

            </tr>
        </table>
                 </ItemTemplate>
    </asp:DataList>
   </div>
  </div>
</div>
        <script>
            // Get the modal
            var modal = document.getElementById('myModal');

            // Get the button that opens the modal
            var btn = document.getElementById("myBtn");

            // Get the <span> element that closes the modal
            var span = document.getElementsByClassName("close")[0];

            // When the user clicks the button, open the modal 
            btn.onclick = function () {
                modal.style.display = "block";
                }

            // When the user clicks on <span> (x), close the modal
            span.onclick = function () {
                modal.style.display = "none";
            }

            // When the user clicks anywhere outside of the modal, close it
            window.onclick = function (event) {
                if (event.target == modal) {
                    modal.style.display = "none";
                }
            }
</script>
    </form>
</body>
</html>

0 个答案:

没有答案