如何使用jQuery的$(文件)。就绪和一个ASP.NET的UpdatePanel在一起吗?如何使用、文件、jQuery、UpdatePanel

2023-09-03 21:08:19 作者:被刻印的时光 ゝ

我摇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.

http://www.asp.net/ajax/documentation/live/overview/AJAXClientEvents.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>