0

我使用应用程序属性来计算在线用户数:

Application["OnlineUsers"] = (int)Application["OnlineUsers"] + 1;  

然后将 Application 属性值绑定到 HTML 标记

<div id="OnlineUser" >
    <span>Number of Online Users is <%=Application["OnlineUsers"].ToString() %></span> 
</div> 

例如,当user1访问页面,DIV标签显示Number of Online Users is 1user2访问页面,DIV标签显示Number of Online Users is 2,但user1仍然Number of Online Users is 1

更改应用程序属性时如何刷新user1页面?user2

4

1 回答 1

0
you can try with Ajax (Timer + Updatepanel)

    <form id="form1" runat="server">
      <asp:ScriptManager runat="server" id="ScriptManager1">
      </asp:ScriptManager>

      <asp:UpdatePanel runat="server" id="UpdatePanel1">
        <ContentTemplate>
          <asp:Timer runat="server" id="Timer1" Interval="10000" OnTick="Timer1_Tick"></asp:Timer>
          <asp:Label runat="server" Text="Page not refreshed yet." id="Label1">
          </asp:Label>
        </ContentTemplate>
     </asp:UpdatePanel>


<div id="test" runat="server" >
</div>


    protected void Timer1_Tick(object sender, EventArgs e)
        {
            test.Text = "Application["OnlineUsers"].ToString();
        }
于 2012-06-25T15:17:52.523 回答