如何在不重新加载页面的情况下让asp.net按钮显示弹出窗口?

时间:2017-03-08 19:49:22

标签: javascript asp.net ajax

通过弹出窗口,我的意思是w3school的弹出式javascript: https://www.w3schools.com/howto/howto_js_popup.asp

我试图将按钮放在Ajax更新面板中,但由于某种原因,javascript函数不会触发。

<asp:ScriptManager ID="ScriptManager" runat="server"></asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <div id="footerbuttons" class="questioncard">
                <div class="popup" onclick="savedPopup()">
                    <asp:Button ID="SaveChangesButton" runat="server" Text="Save Changes" OnClick="SaveChangesButton_Click" BackColor="#F9AF19" Font-Size="Medium" />
                    <span class="popuptext" id="savedPopup">Saved!</span>
                </div>
                <div class="popup" onclick="sentPopup">
                    <asp:Button ID="SubmitButton" runat="server" Text="Submit to Supervisor" OnClick="SubmitButton_Click" BackColor="#F9AF19" Font-Size="Medium"/>
                    <span class="popuptext" id="sentPopup">Sent!</span>
                </div>
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>


    <script type="text/javascript">
    function savedPopup() {
        var popup = document.getElementById("savedPopup");
        eval(popup.classList.toggle("show"));
    }

    function sentPopup() {
        var popup = document.getElementById("sentPopup");
        eval(popup.classList.toggle("show"));
    }
    </script>

1 个答案:

答案 0 :(得分:0)

我认为您需要在关闭ContentTemplate标记后添加asyncPostBackTrigger。

   <Triggers>
 <asp:AsyncPostBackTrigger ControlID="SaveChangesButton" EventName="Click" />
 <asp:AsyncPostBackTrigger ControlID="SubmitButton" EventName="Click" />
   </Triggers>

然后在Code背后

SaveChangesButton按钮的Click事件

ScriptManager.RegisterStartupScript(this, this.GetType(), "savedPopup", "savedPopup();", true);

和SubmitButton按钮的Click事件

ScriptManager.RegisterStartupScript(this, this.GetType(), "sentPopup", "sentPopup();", true);