0

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...
}
1

1 Answer 1

1

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);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.