繁体   English   中英

Modal Popup在UpdatePanel内部不起作用

[英]Modal Popup not working inside UpdatePanel

我在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();
    });
}

网格视图:

<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和注册模态弹出窗口的代码

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模态,因此它包含jquery.reveal.js文件,其中包含揭示功能。 函数popupModal在我单独的js文件employee.js中。 由于错误消息是这样的,例如``对象不支持IE中的属性或方法''显示'',我假设一旦首次显示弹出模式,它就无法从jquery.reveal中找到显示功能。 .js文件。

谁能帮我解决这个问题?

桑耶夫

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

可能发生的事情是jquery和updatepanels之间发生的相同冲突(知道您没有使用jquery,但我确定它是同一类型的问题)。 基本上,updatepanel不会刷新整个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

除非您执行以下操作,否则jQuery无法与updatePanels配合使用:

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

暂无
暂无

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

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