2017-01-16 27 views
0

我有一個javascript,在我的gridview上添加了一個搜索框。它加載與頁面:在aspx計時器內執行javascript

<script type="text/javascript"> 
$(document).ready(function() { 
    $('<thead></thead>').prependTo('table#ctl00_MainContent_GVOPL').append($('table#ctl00_MainContent_GVOPL tr:first')); 
    $('table#ctl00_MainContent_GVOPL tbody tr').quicksearch({ 
     reset: true, 
     resetClass: "resetButton", 
     resetLabel: "Zurücksetzen", 
     position: 'before', 
     attached: 'table#ctl00_MainContent_GVOPL', 
     stripeRowClass: ['odd', 'even'] 
    }); 
    $(".qs_input").focus(); 
}); 

具有定時更新我在GridView。第一次更新後,搜索框消失。這個想法是添加JavaScript來執行也在計時器。但我該怎麼做?

定時器:

<asp:Timer ID="Timer1" runat="server" Interval="5000" ontick="Timer1_Tick" /> 

protected void Timer1_Tick(object sender, EventArgs e) 
{ 
    ...build my gridview... 
} 
+0

嘗試這樣的: - http://stackoverflow.com/a/4994129/7036750 –

回答

1

你需要調用一個回發

後再次搜索框的結合環繞你的JavaScript函數中的

<script type="text/javascript"> 
    $(document).ready(function() { 
     bindSearchBox(); 
    }); 

    function bindSearchBox() { 
     $('<thead></thead>').prependTo('table#ctl00_MainContent_GVOPL').append($('table#ctl00_MainContent_GVOPL tr:first')); 
     ..... 
    } 
</script> 

然後調用從代碼的功能在定時器Tick中重新加載GridView時。

protected void Timer1_Tick(object sender, EventArgs e) 
{ 
    //...build my gridview... 
    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "bindBox", "bindSearchBox()", true); 
} 
+0

運行完美,謝謝! –