简体   繁体   English

从代码隐藏关闭时,Foundation 6模态叠加保持不变

[英]Foundation 6 modal overlay stays when closing from codebehind

I have a page that shows a list of items, on clicking a button by an item, a modal containing a form pops-up for the user to edit the item. 我有一个页面,其中显示了一个项目列表,单击某个项目的按钮时,会弹出一个模式,其中包含一个窗体,供用户编辑该项目。 When they click the relevant button, the data is updated by the code behind and the modal should close. 当他们单击相关按钮时,数据将由后面的代码更新,并且模式应关闭。

What happens: The data is being saved correctly, the form within the modal disappears but the overlay (background) remains in place so the page can't be used. 发生的情况:数据已正确保存,模式中的表单消失了,但是覆盖(背景)保留在原处,因此无法使用该页面。 Why isn't the overlay closing? 为什么覆盖层不关闭?

JavaScript: JavaScript:

    function openthemodal() {
        var popup = new Foundation.Reveal($('#exampleModal1'));
        popup.open();
    }

    function closethemodal() {
        eventFire(document.getElementById('btnclosebutton'), 'click');
    }

    function eventFire(el, etype) {
        if (el.fireEvent) {
            el.fireEvent('on' + etype);
        } else {
            var evObj = document.createEvent('Events');
            evObj.initEvent(etype, true, false);
            el.dispatchEvent(evObj);
        }
    }

HTML (excerpt): HTML(节选):

<div class="reveal" id="exampleModal1" data-reveal>
    <h3><asp:Label runat="server" ID="lblexpensetitle"></asp:Label></h3>
    <!-- Form code here -->
    <button id="btnclosebutton" class="close-button" data-close aria-label="Close modal" type="button">
    <span aria-hidden="true">&times;</span>
    </button>

    <a href="javascript:closethemodal();">Close Modal</a>
</div>

Clicking on the "Close Modal" link and the "close" button in the modal work fine. 单击模态中的“关闭模态”链接和“关闭”按钮即可。

c# code to open and close the modal C#代码打开和关闭模态

ScriptManager.RegisterStartupScript(this, typeof(Page), "openmodal", "javascript:openthemodal();", true);
ScriptManager.RegisterStartupScript(this, typeof(Page), "closemodal", "javascript:closethemodal();", true);

UPDATE 1 更新1

Realised I hadn't pointed out the modal is within an UpdatePanel, don't know if that makes a difference. 意识到我没有指出模式是在UpdatePanel中,不知道这是否有所作为。

Why do you use your own method to make a click if you're using jQuery? 如果使用jQuery,为什么要使用自己的方法进行点击? You can do it in one line: 您可以一行完成:

$('#btnclosebutton').click()

As for overlay, that's kinda strange. 至于覆盖,这有点奇怪。 You can add this line to closethemodal() function to hide it: 您可以将此行添加到closethemodal()函数以将其隐藏:

$('#btnclosebutton').parent('.reveal').parent('.reveal-overlay').hide();

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

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