从带有计时器的更新面板内部的代码后面调用Jquery函数

问题描述 投票:0回答:1

在Web表单上,我在更新面板中有一个计时器控件,在另一个更新面板中有几个表单元素,如下代码:

。aspx文件

        <asp:UpdatePanel ID="updPnlTimer" runat="server">
            <ContentTemplate>
                <asp:Timer runat="server" ID="timerMeeting" Interval="5000" OnTick="timerMeeting_Tick"></asp:Timer>
            </ContentTemplate>
        </asp:UpdatePanel>

    <asp:UpdatePanel runat="server" ID="updPnlMeeting" UpdateMode="Conditional">
            <ContentTemplate>
                <div class="row">
                    <div class="col-sm-12" style="min-height: 60px;">
                    .
                    .
                    .
                    .
                    </div>
            </ContentTemplate>               
        </asp:UpdatePanel>

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

    });

    $(function scrolltoActive() {

        $('html, body').animate({scrollTop: $(".trfocus").offset().top}, 2000);
    });

</script>

trfocus类被动态添加到表的特定行(在运行时)

。aspx.cs文件

     protected void timerMeeting_Tick(object sender, EventArgs e)
     {
        GetAgendaList(Request.QueryString["t"]);
     }

    void GetAgendaList(string token)
    {
        if (!string.IsNullOrWhiteSpace(token))
        {
        ..
        ...
        ...
        .....
        ltrAgendaList.Text = sbAgendaList.ToString();
        ltrMeetingDetails.Text = sbMeeting.ToString();
        updPnlMeeting.Update();

        ScriptManager.RegisterStartupScript(this.Page, this.GetType(), Guid.NewGuid().ToString(), "scrolltoActive();", true);
        }
    }

5秒后,我希望页面自动滚动到表格的特定行,而不刷新页面,但是我无法做到这一点。 chrome控制台上显示的错误是

Uncaught ReferenceError: scrolltoActive is not defined

Pleeeease帮助

jquery asp.net timer webforms updatepanel
1个回答
0
投票

尝试

string scrollScript = "function pageLoad(sender, args) { if (args.get_isPartialLoad()) {scrolltoActive(); }}";
ScriptManager.RegisterStartupScript(
            this, 
            GetType(), 
            "scrolltoActive", 
            scrollScript, 
            true
        );
© www.soinside.com 2019 - 2024. All rights reserved.