jQuery sorttable doens't work after postback in updatepanel (JavaScript)

梦想的初衷 提交于 2019-12-03 15:19:52

问题


I have a issue with the sortable function of jQuery. When my page does a post-back with the update-panel the sorting of the dynamic table doesn't work anymore. The post-back is triggerd when a image-button is pushed. When the image-button is pushed there is a new row with a subtable in it.

I tried these 3 JavaScript codes but they all only seem to work for the first time. They DON'T work after I open the subtable.

Do you guys maybe know a JavaScript solution to solve this?

My first try:

$(function(){
        $('table[id*="tbl_main"]').tablesorter();
    });

My second try:

$(document).ready(function(){
        $('table[id*="tbl_main"]').tablesorter();
    });

My third try:

function pageLoad() {
        $(function () {
            $("#pager").unbind();
            $('table[id*="tbl_main"]')
            .tablesorter()
            .tablesorterPager({ container: $("#pager") });
        }
    )}

回答1:


After each update all scripts are removed, you have to bind them again like:

<asp:UpdatePanel ID="UpdatePanel1" runat="server">

     <ContentTemplate>
          <script type="text/javascript">
               Sys.Application.add_load(BindFunctions);
          </script>
...

And then in your javascript file:

function BindFunctions() {
$('table[id*="tbl_main"]').tablesorter();
};


来源:https://stackoverflow.com/questions/15497630/jquery-sorttable-doenst-work-after-postback-in-updatepanel-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!