updatepanel __dopostback 命中 .update() 但不刷新

发布于 2024-07-24 14:13:49 字数 350 浏览 1 评论 0原文

我有一个包含两个更新面板的页面,每个面板都有一个动态生成的网格视图。 Updatepanel1 在计时器上每十秒刷新一次。 当在第一个网格中选择一个项目时,第二个更新/网格将刷新。

我正在尝试使用 __doPostBack 来完成这项壮举。 此方法确实到达服务器并在 updatepanel2 上运行我的 .update。 我看到 updatepanel2 获取数据,但表单实际上从未更新 updatepanel2。

仅当 updatepanel1 计时器计时并且我将 updatepanel2 模式设置为“始终”时,我才能让 updatepanel2 显示数据。

有人有什么建议吗?

谢谢

I have a page with two update panels each of which has a gridview generated dynamically. Updatepanel1 refreshes every ten seconds on a timer. The second update/grid refreshes when an item is selected in the first grid.

I'm trying to accomplish this feat using __doPostBack. This method does reach the server and run my .update on updatepanel2. I see that updatepanel2 gets data, but the form never actually updates updatepanel2.

I can get updatepanel2 to display data only when updatepanel1 timer ticks and I set updatepanel2 mode to "Always".

anyone have any suggestions?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

瀟灑尐姊 2024-07-31 14:13:49

好吧,我解决了这个问题。 我修改为使用以下方法进行 doPostBack 调用。

http://encosia.com/2007/07 /13/easily-refresh-an-updatepanel-using-javascript/

希望这会有所帮助。

Well I fixed this problem. I modified to using the following method for the doPostBack call.

http://encosia.com/2007/07/13/easily-refresh-an-updatepanel-using-javascript/

Hope this helps.

沧桑㈠ 2024-07-31 14:13:49

我看到您回答了自己的问题,但为了其他人的利益,为什么不在计时器上设置两者以按指定的时间间隔刷新,或者作为带有“UpdatePanel1.Update()”的 Tick 事件方法,而不是 doPostBack()在方法的最后? 为此,您需要在 Default.aspx 页面代码本身中设置间隔; 我选择了 10 毫秒,这样它就可以显示非常快速的操作的进度:

<asp:ScriptManager ID="ScriptManager1" runat="server" AsyncPostBackTimeout="360000" />
<asp:Button ID="btnDoSomething" runat="server" Text="Do Something" OnClick="btnDoSomething_Click" />
 <asp:UpdatePanel ID="UpdatePanel1" runat="server" OnLoad="UpdatePanel1_Load" UpdateMode="conditional"> 
    <ContentTemplate>
        <span id="spnLabel" runat="server">
        <asp:Timer ID="Timer1" runat="server" Interval="10" OnTick="Timer1_Tick"></asp:Timer> 
    </ContentTemplate>         
    <Triggers >
        <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
    </Triggers>
 </asp:UpdatePanel> 

然后在代码隐藏中添加一个 Timer1_Tick 方法,当您有更新时调用该方法 - 在此示例中,从 btnDoSomething_Click() 添加到 spnLabel.InnerHtml 的内容方法:

protected void btnDoSomething_Click(object sender, EventArgs e)
{
     Timer1.Enabled = true;
     Timer1.Interval = 10;
     Timer1_Tick(sender, e);
     Timer1.Enabled = false;
}
protected void Timer1_Tick(object sender, EventArgs e)
{
     spnLabel.InnerHtml = "hi";
     UpdatePanel1.Update();
}

请记住,刷新是由 Timer 间隔控制的,而不是由调用 Timer1_Tick(sender,e) 的时间控制的,即使最后有 UpdatePanel1.Update() - 例如,如果将间隔设置为 10000,它也会即使您的操作在此之前多次使用过 Timer1_Tick() 方法,也会在 10 秒后更新。 不管怎样,最后你仍然需要一个 UpdatePanel1.Update() 。

-汤姆

I see you answered your own question, but for the benefit of others, instead of doPostBack(), why not set both on a Timer to refresh at a specified interval, or as a Tick event method with an "UpdatePanel1.Update()" at the end of the method? For this way, you'd need to set the interval in the Default.aspx page code itself; I picked 10ms so it could show the progress for a very fast operation:

<asp:ScriptManager ID="ScriptManager1" runat="server" AsyncPostBackTimeout="360000" />
<asp:Button ID="btnDoSomething" runat="server" Text="Do Something" OnClick="btnDoSomething_Click" />
 <asp:UpdatePanel ID="UpdatePanel1" runat="server" OnLoad="UpdatePanel1_Load" UpdateMode="conditional"> 
    <ContentTemplate>
        <span id="spnLabel" runat="server">
        <asp:Timer ID="Timer1" runat="server" Interval="10" OnTick="Timer1_Tick"></asp:Timer> 
    </ContentTemplate>         
    <Triggers >
        <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
    </Triggers>
 </asp:UpdatePanel> 

Then have a Timer1_Tick method in the code-behind that you call when you have an update - in this example, something to add to spnLabel.InnerHtml from a btnDoSomething_Click() method:

protected void btnDoSomething_Click(object sender, EventArgs e)
{
     Timer1.Enabled = true;
     Timer1.Interval = 10;
     Timer1_Tick(sender, e);
     Timer1.Enabled = false;
}
protected void Timer1_Tick(object sender, EventArgs e)
{
     spnLabel.InnerHtml = "hi";
     UpdatePanel1.Update();
}

Remember that the refresh is controlled by the Timer interval, not by when you call Timer1_Tick(sender,e), even if you have an UpdatePanel1.Update() at the end - example, if you set the interval to 10000, it would update after 10 seconds, even if your operation had used the Timer1_Tick() method several times before then. You would still need an UpdatePanel1.Update() at the end, regardless, though.

-Tom

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文