如何使用jQuery的$(文件)。就绪和一个ASP.NET的UpdatePanel在一起吗? [英] How do I use a jQuery $(document).ready and an ASP.NET UpdatePanel together?

查看:114
本文介绍了如何使用jQuery的$(文件)。就绪和一个ASP.NET的UpdatePanel在一起吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我摇javascipt的这个位在< HEAD> 我的网页的部分:

I'm rocking this bit of Javascipt in the <head> section of my page:

<script type="text/javascript">
    $(document).ready(function() {
        $('dl.expander dd').expander
        (
            {   slicePoint: 50,    widow: 2,   expandEffect: 'show', userCollapseText: '[^]' }
        );
    });
</script>

这伟大工程的第一次加载页面;然而,当我点击了&LT; ASP:按钮&GT; 这是一个&LT内部; ASP:UpdatePanel的&GT; 页是局部刷新,但 $(文件)。就绪永远不会再次调用。

This works great the first time the page is loaded; however, when I click an <asp:button> that is inside an <asp:updatepanel> the page is partially refreshed, but the $(document).ready is never called again.

这是很重要的,因为这个JavaScript在 $(文件)。就绪部分坍塌,并加入了readmore选项pararaphs(或DL的与名单页面,其中大部分应该是默认瘫倒在类=膨胀)。

This is important, because this Javascript in the $(document).ready section is collapsing and adding a "readmore" option to a list of pararaphs (or dl's with class="expander") on the page, most of which should be collapsed by default.

推荐答案

您将需要一个处理程序添加到了AJAX客户端endRequest事件。更多信息请参见下面的链接。当AJAX发动机完成一个请求到服务器,并且是必要的有关内容的更新面板内的任何的javascript运行此事件将被调用。

You will need to add a handler to the AJAX client side endRequest event. See the links below for more information. This "event" is called when the ajax engine completes a request to the server, and is necessary for any javascript running on content that is inside the update panel.

<一个href="http://www.asp.net/ajax/documentation/live/overview/AJAXClientEvents.aspx">http://www.asp.net/ajax/documentation/live/overview/AJAXClientEvents.aspx

<一个href="http://msdn.microsoft.com/en-us/library/bb383810.aspx">http://msdn.microsoft.com/en-us/library/bb383810.aspx

<script type="text/javascript">
    $(function() {
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
    });

    function EndRequestHandler(sender, args) {
        // code that you want to run when the request is complete
    }
<script>

这篇关于如何使用jQuery的$(文件)。就绪和一个ASP.NET的UpdatePanel在一起吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆