模态弹出窗口在 UpdatePanel 内不起作用

发布于 2025-01-01 11:30:50 字数 2868 浏览 1 评论 0 原文

我在 UpdatePanel 中有一个 gridview 。 gridview 中的一列是链接,单击时应显示模态(我正在使用 zurb modal 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 并注册模态弹出窗口的代码

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,代码在它所在的行中断 显示弹出窗口

 函数 popupModal()
    {
        $("a.link").click(function (e) {
            e.preventDefault();
            $('#myModal #modalContents').load($(this).attr('href'));
            $('#myModal').reveal(); -> [在这一行中抛出错误。]
        });
    }

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

谁能帮我解决这个问题?

桑吉耶夫

I have a gridview inside UpdatePanel. One of the column in gridview is link which when clicked should display modal (i am using zurb modal http://www.zurb.com/playground/reveal-modal-plugin). The problem is the modal only gets displayed only once when the link is clicked, the next time when the link is clicked it just refreshes the page. The modal should be displayed everytime when the link inside the gridview is clicked.

Modal Script:

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">×</a>            
    </div>

Code To Bind GridView and Register 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);

}

Edit: I tried to debug javascript and the code breaks in line where it
reveals the popup

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

Since i am using zurb modal, it consists of jquery.reveal.js file
which consists of reveal function. The function popupModal is in my
separate js file employee.js. Since the error message is something
like this 'Object doesn't support property or method 'reveal' in IE, i
am assuming once the popup modal gets displayed for the first time, it
can't find the reveal function from the jquery.reveal.js file.

Can anyone help me fix this issue?

Sanjeev

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

青柠芒果 2025-01-08 11:30:50

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

ok finally found the solution. didn't know but you couldn't reference jquery.js file twice in the project. I had reference to my jquery.js file in Master file and i had same reference in my Department.aspx file. Got rid of duplicate jquery reference and it just worked fine.

傾旎 2025-01-08 11:30:50

可能发生的情况与 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

What's probably happening is the same conflict that happens between jquery and updatepanels ( know you're not using jquery, but i'm sure it's the same type of issue). Basically the updatepanel is not refreshing the entire DOM so the other js library's functions never get called. Here's a blog post on dealing with it.

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

南巷近海 2025-01-08 11:30:50

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

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

Jquery doesn't play nice with updatePanels unless you do the following:

function pageLoad() {
  //Your Jquery code goes here...
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文