【问题标题】:Execute javascript within aspx timer在 aspx 计时器内执行 javascript
【发布时间】:2017-01-16 12:17:11
【问题描述】:

我有一个 javascript,在我的 gridview 上添加了一个搜索框。它与页面一起加载:

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

【问题讨论】:

标签: javascript asp.net timer


【解决方案1】:

PostBack 后需要再次调用搜索框的绑定

将 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>

然后在 Timer Tick 中重新加载 GridView 时从后面的代码中调用该函数。

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

【讨论】:

    猜你喜欢
    • 2021-11-07
    • 1970-01-01
    • 2011-09-25
    • 1970-01-01
    • 2023-04-07
    • 2010-10-15
    • 1970-01-01
    • 2015-06-13
    • 2015-02-27
    相关资源
    最近更新 更多