【问题标题】:Modal Popup not working inside UpdatePanel模态弹出窗口在 UpdatePanel 中不起作用
【发布时间】:2012-02-01 19:48:28
【问题描述】:

我在 UpdatePanel 中有一个 gridview。 gridview 中的一列是链接,单击时应显示模态(我使用的是 zurb 模态http://www.zurb.com/playground/reveal-modal-plugin)。问题是模式只在单击链接时显示一次,下次单击链接时它只会刷新页面。每次点击gridview内的链接时,都会显示模态框。

模态脚本:

function popupModal()
{
    $("a.link").click(function (e) {
        e.preventDefault();
        $('#myModal #modalContents').load($(this).attr('href'));
        $('#myModal').reveal();
    });
}

GridView:

<asp:ScriptManager ID="smgr" runat="server" EnablePartialRendering="true" />
<asp:UpdatePanel ID="upnlSearchResults" runat="server" RenderMode="Inline">
    <ContentTemplate>       
        <asp:GridView ID="gvResult" runat="server" AutoGenerateColumns="false">                   
            <Columns>
                <asp:BoundField DataField="EmployeeID" HeaderText="Employee ID"  />
                <asp:TemplateField HeaderText="">
                    <ItemTemplate>
                        </td></tr>
                        <tr>
                            <td colspan="10">
                                <a href="Department.aspx" class="link">Detail Information</a>
                            </td>
                        </tr>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="btnSearch" />
    </Triggers>
</asp:UpdatePanel>

    <div id="myModal" class="reveal-modal">
         <div id="modalContents"></div>
         <a class="close-reveal-modal">&#215;</a>            
    </div>

绑定 GridView 和注册 Modal PopUp 的代码

protected void btnSearch_Click(object sender, ImageClickEventArgs e)
{
    var results = _presenter.GetEmployers();
    gvResult.DataSource = results;
    gvResult.DataBind();

    ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "popUp", "popupModal();", true);

}

编辑:我尝试调试 javascript 并且代码在它所在的行中中断 显示弹出窗口

   function popupModal()
    {
        $("a.link").click(function (e) {
            e.preventDefault();
            $('#myModal #modalContents').load($(this).attr('href'));
            $('#myModal').reveal(); -> [throws error in this line.]
        });
    }

由于我使用的是 zurb modal,它由 jquery.reveal.js 文件组成 其中包括显示功能。功能 popupModal 在我的 单独的js文件employee.js。由于错误消息是某事 像这样'对象不支持 IE 中的属性或方法'显示',我 我假设一旦第一次显示弹出模式,它 在 jquery.reveal.js 文件中找不到显示函数。

谁能帮我解决这个问题?

桑吉夫

【问题讨论】:

    标签: javascript asp.net updatepanel modal-dialog scriptmanager


    【解决方案1】:

    好的,终于找到了解决方案。不知道,但您不能在项目中两次引用 jquery.js 文件。我在主文件中引用了我的 jquery.js 文件,在我的 Department.aspx 文件中有相同的引用。摆脱了重复的 jquery 引用,它工作得很好。

    【讨论】:

    【解决方案2】:

    可能发生的情况与 jquery 和 updatepanels 之间发生的冲突相同(知道您没有使用 jquery,但我确信这是同一类型的问题)。基本上更新面板不会刷新整个 DOM,因此其他 js 库的函数永远不会被调用。这是一篇关于如何处理它的博客文章。

    http://weblogs.asp.net/hajan/archive/2010/10/07/make-them-to-love-each-other-asp-net-ajax-updatepanels-amp-javascript-jquery-functions.aspx

    【讨论】:

    • ajax 控件工具包有一个模式弹出窗口,可以很好地与更新面板配合使用,asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/ModalPopup/…
    • 我从博客网站尝试了这些方法,但问题仍然存在。模态仅显示一次,但一旦模态关闭并单击 gridview 中的链接,模态将不会显示。
    【解决方案3】:

    Jquery 不能很好地与 updatePanels 配合使用,除非您执行以下操作:

    function pageLoad() {
      //Your Jquery code goes here...
    }
    

    【讨论】:

    • 我试过了,但问题仍然存在。模态仅显示一次,但一旦模态关闭并单击 gridview 中的链接,模态将不会显示。
    猜你喜欢
    • 2012-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多