Reputation: 2176
I have a javascript with adds a searchbox over my gridview. It loads with the page:
<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();
});
With a timer I update the gridview. After the first update the searchbox disappear. The idea is to add the javascript to execute also in the timer. But how can I do that?
Timer:
<asp:Timer ID="Timer1" runat="server" Interval="5000" ontick="Timer1_Tick" />
protected void Timer1_Tick(object sender, EventArgs e)
{
...build my gridview...
}
Upvotes: 0
Views: 1536
Reputation: 35514
You need to call the binding of the searchbox again after a PostBack
Wrap your Javascript in a function
<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>
And then call that function from code behind when reloading the GridView in a Timer Tick.
protected void Timer1_Tick(object sender, EventArgs e)
{
//...build my gridview...
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "bindBox", "bindSearchBox()", true);
}
Upvotes: 1