【问题标题】:Lazy Loading using Updatepanel and Timer in C#在 C# 中使用 Updatepanel 和 Timer 进行延迟加载
【发布时间】:2011-07-22 19:43:23
【问题描述】:

通过计时器加载更新面板后,我无法从更新面板发出任何异步请求。

示例aspx代码:

<asp:UpdatePanel runat="server" UpdateMode="Conditional">
<ContentTemplate>

    <%--The Timer that causes the partial postback--%>
    <asp:Timer runat="server" Interval="100" OnTick="Timer_Tick" Id="Timer1"/>                

    <asp:ImageButton ID="btnSaveEmployeePrevJobs" runat="server" ImageAlign="AbsBottom"
    ImageUrl="~/Images/saveOff.gif" onmouseout="this.src='../Images/saveOff.gif'"
    onmouseover="this.src='../Images/saveOn.gif'" OnClick="btnSaveEmployeePrevJobs_Click"/>

</ContentTemplate>

服务器端代码:

private void Timer_Tick(object sender, EventArgs args)
{
    Timer1.Enabled = false;
    //some code
}

protected void btnSaveEmployeePrevJobs_Click(object sender, EventArgs e)
{
    // some code
}

问题:无法引发点击事件 单击按钮时,基本上 Timer 得到 启用(不知道为什么)并调用 再次自己而不是调用 click 事件..

提前谢谢..

【问题讨论】:

    标签: .net asp.net c#-4.0 asp.net-ajax


    【解决方案1】:

    我会改用 jQuery,因为我认为 100 毫秒非常小,因此您的服务器端代码可能仍在加载并被执行,在计时器计时超过 2 次左右之后。

    加载你的 DOM,编写一个简单的 jQuery 函数来从你的服务器获取你的数据,将它填充到你的页面中,然后微笑 :)

    【讨论】:

    • 我只是在优化现有的代码,它是建立在更新面板上的,所以使用 jquery 将是一个巨大的变化.. :(
    【解决方案2】:

    您是否尝试过:

    protected void Timer1_Tick(object sender, EventArgs e)
    {
        //Timer1.Enabled = false;
        Label1.Text = "Panel refreshed at: " + DateTime.Now.ToLongTimeString();
    }
    

    注意,如果你设置UpdateMode="Conditional",你需要显式调用UpdatePanel.Update();否则删除该属性。

    结帐:Tutorial: How to refresh an UpdatePanel control at a timed interval

    【讨论】:

      【解决方案3】:

      最后我已经解决了我的问题,这是视图状态(在会话中存储视图状态)和异步请求之间的冲突......它给出了新的编号。到回发的视图状态。

      感谢您的宝贵时间...

      【讨论】:

        猜你喜欢
        • 2013-03-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-08-30
        • 2011-01-09
        • 2017-07-08
        • 1970-01-01
        相关资源
        最近更新 更多