Jquery Facebook 自动完成功能在更新面板回发后消失

发布于 2024-09-30 03:54:40 字数 487 浏览 0 评论 0原文

嘿, 我在 asp.net ajax 更新面板中使用 Facebook 风格的 autoComplete, 问题是当我回发到 UpdatePanel 时,Jquery 消失了, 有什么想法吗?

谢谢,

代码:

$(document).ready(function () {


$("[id$='DDL_Guests']").fcbkcomplete({
    json_url: "../../Search.asmx/SearchAC",
    cache: false,
    filter_case: false,
    filter_hide: true,
    firstselected: true,
    onremove: RemoveItem,
    onselect: AddItem,
    filter_selected: true,
    maxitems: 10,
    newel: true
});

});

hey,
i'm using the Facebook style autoComplete inside a asp.net ajax update panel,
by problem is when im doing a postback to the UpdatePanel the Jquery Disapear,
Any Idead?

thanks,

Code:

$(document).ready(function () {


$("[id$='DDL_Guests']").fcbkcomplete({
    json_url: "../../Search.asmx/SearchAC",
    cache: false,
    filter_case: false,
    filter_hide: true,
    firstselected: true,
    onremove: RemoveItem,
    onselect: AddItem,
    filter_selected: true,
    maxitems: 10,
    newel: true
});

});

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

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

发布评论

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

评论(1

一人独醉 2024-10-07 03:54:40

当发生部分回发时,它会更新您的标记,因此 ID 为 DDL_Guests 的元素将不再绑定到您第一次加载页面时使用的 jQuery 代码。

因此,在部分回发事件发生后,您需要重新绑定 jQuery 代码。

要解决此问题,您必须在代码中添加一个 endRequest 事件处理程序,并调用一个函数,该函数将再次将小部件重新绑定到 DDL_Guests 元素,如以下代码所示

$(document).ready(function () {
    jQueryInit();
});

function load() { 
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(jQueryInit); 
} 

function jQueryInit() { 
    $("[id$='DDL_Guests']").fcbkcomplete({
        json_url: "../../Search.asmx/SearchAC",
        cache: false,
        filter_case: false,
        filter_hide: true,
        firstselected: true,
        onremove: RemoveItem,
        onselect: AddItem,
        filter_selected: true,
        maxitems: 10,
        newel: true
    });            
} 

然后简单地 使用此技巧从正文标记中调用 load 函数,

<body onload="load()">

您的 jQueryInit() 函数中的 jQuery 代码在第一次通过 $(document ).ready(function () {} 并在 UpdatePanel 引起的部分页面回发后再次重新绑定

希望它有帮助

When a partial postback occurs it update your markup and so the element with ID DDL_Guests will not be anymore binded to the jQuery code you are using the first time the page load.

So you need to rebind your jQuery code after a partial postback event has occurred.

To solve this problem you have to add an endRequest event handler in your code and call a function that will rebind again the widget to the DDL_Guests element as in the following code

$(document).ready(function () {
    jQueryInit();
});

function load() { 
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(jQueryInit); 
} 

function jQueryInit() { 
    $("[id$='DDL_Guests']").fcbkcomplete({
        json_url: "../../Search.asmx/SearchAC",
        cache: false,
        filter_case: false,
        filter_hide: true,
        firstselected: true,
        onremove: RemoveItem,
        onselect: AddItem,
        filter_selected: true,
        maxitems: 10,
        newel: true
    });            
} 

Then simply call the load function from your body markup

<body onload="load()">

using this trick your jQuery code inside the jQueryInit() function get binded the first time the page load through the $(document).ready(function () {} and get rebinded again after a partial page postback caused by the UpdatePanel

Hope it helps

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