【问题标题】:ImageButton in Updatepanel fires only on first Page LoadUpdatepanel 中的 ImageButton 仅在第一个页面加载时触发
【发布时间】:2015-03-24 08:56:19
【问题描述】:

我有以下更新面板:

<asp:UpdatePanel ID="upPopUps" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:Panel ID="panelOverlay" runat="server" class="Overlay" Visible="false">
        </asp:Panel>
        <asp:Panel ID="panelPopUpPanel" runat="server" class="PopUpPanel" Visible="false"
            BorderStyle="Solid" BorderWidth="5px" Height="250px">
            <table style="width: 100%; height: 100%; border-bottom: solid 2; border-top: solid 2;
                border-left: solid 2; border-right: solid 2;">
                <tr>
                    <th style="width: 100%; padding-left: 10px;" colspan="2">
                        <asp:PlaceHolder ID="PopupHeader" runat="server"></asp:PlaceHolder>
                    </th>
                    <th>
                        <asp:ImageButton id="cmdClosePopUp" runat="server" src="../Navigation/PopupImages/Close.png" alt="Close Popup"
                            OnClick="ClosePopup"  align="right" />
                    </th>
                </tr>
                <tr class="border_top">
                    <td colspan="3">
                    </td>
                </tr>
                <tr style="height: 80%">
                    <td align="center">
                        <asp:PlaceHolder ID="PopupMessage" runat="server"></asp:PlaceHolder>
                    </td>

                </tr>
                <tr style="height: 10%">
                    <td colspan="3" style="padding-left: 10px;">
                        <input type="hidden" id="StartDivID" value="0" runat="server" />
                        <input type="hidden" id="NewsCount" value="" runat="server" />
                        <asp:ImageButton runat="server" id="btn_ok" src="../Navigation/PopupImages/Ok_Button.jpg" alt="Close Popup"
                              OnClick="ClosePopup" align="right" />
                    </td>
                </tr>
            </table>
        </asp:Panel>
    </ContentTemplate>
</asp:UpdatePanel>

我的问题是,如果我在 PageLoad 之后单击这两个按钮之一,它可以正常工作。

通过$(document).ready(function(),我每 60 秒刷新一次页面。弹出弹出窗口,但按钮不再触发。

        $(document).ready(function() {

                setInterval("RefreshGrid()", 60000);

        });


        function RefreshGrid() {
            var WebGrid1 = ISGetObject("WebGrid1");
            WebGrid1.Refresh();
        }

有人有想法吗,问题可能出在哪里?为什么它只适用于第一个页面加载?

【问题讨论】:

  • 你到底在$(document).ready(function() { })做什么?
  • 刷新后是否尝试过重新绑定事件? $('#btn_ok').click(...
  • 我必须在哪里执行此操作?在准备功能?你能给我一个例子吗?谢谢
  • 把它放在WebGrid1.Refresh(); 电话下面:)
  • 我现在试过了,但还是不行 :(。是否可以在服务器端的 PageLoad 上重新绑定或注册按钮?

标签: c# asp.net .net updatepanel


【解决方案1】:

有一个名为pageLoad 的保留函数在每次回发时运行。在里面绑定你的事件。

function pageLoad() {
    $('#btn_ok, #cmdClosePopUp').click(ClosePopup); //Something like this.
}

感觉就像在刷新时丢失了指向处理程序的链接。这应该可以解决这个问题。

【讨论】:

  • 另一种解决方案是使用带有图像的 asp:Linkbutton 或普通的 asp:button。使用该按钮,代码隐藏每次都会触发,而无需重新绑定事件。我不知道为什么 ImageButton 不起作用。
猜你喜欢
  • 2013-10-24
  • 2023-04-06
  • 1970-01-01
  • 2011-03-24
  • 1970-01-01
  • 2011-06-24
  • 2014-10-02
  • 1970-01-01
  • 2021-10-19
相关资源
最近更新 更多