ASP.NET/AJAX - 从外部触发的 Web 用户控件更新面板

发布于 2024-08-31 02:16:42 字数 111 浏览 2 评论 0原文

我有一个带有更新面板的网络用户控件。在我的主页上我有大约 3 个这样的控件。现在我想在主页中有一个计时器,它将触发网络用户控件中的更新面板。

我该如何处理这个问题?

提前致谢。

I've got an web user control with an updatepanel. On my mainpage I got like 3 of those controls. Now I want to have an timer in the mainpage which would trigger the updatepanels in the web user controls.

How can I manage this?

Thanks in advance.

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

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

发布评论

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

评论(1

左耳近心 2024-09-07 02:16:42

使用 AJAX Timer 控件作为 UpdatePanel 触发器

UserControl 调用其更新面板的更新函数,并从每个控件的 TimerTick-Event 中的主页调用它。
设置 UserControls 的 UpdatePanels 的 UpdateMode=Conditional。

例如,在您的用户控件的代码隐藏中:

Public Sub Update()
    'bind Data to your UpdatePanel's content f.e.:
    Me.Label1.Text = Date.Now.ToLongTimeString
    Me.UpdatePanel1.Update()
End Sub

在您的主页中:

Private myControls As New List(Of WebUserControl1)

Private Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
     For i As Int32 = 1 To 10
        Dim newControl As WebUserControl1= DirectCast(LoadControl("./WebUserControl1.ascx"), WebUserControl1)
        myControls.Add(newControl)
        MainPanel.Controls.Add(newControl)
     Next
End Sub

Protected Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    'in this example added dynamically
    For Each ctrl As WebUserControl1 In Me.myControls 
        ctrl.Update()
    Next
End Sub

在用户控件的 ascx 文件中:

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>             
    </ContentTemplate>
</asp:UpdatePanel>

在主页的 aspx 文件中:

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
     <asp:Panel ID="MainPanel"  runat="server">
        <asp:Timer ID="Timer1" runat="server" Interval="1000"></asp:Timer>
     </asp:Panel>             
    </ContentTemplate>
</asp:UpdatePanel>

Using the AJAX Timer Control as an UpdatePanel Trigger

Implement an Update-Function in your UserControl which calls the Update-Function of their Update-Panels and call it from the Mainpage in the TimerTick-Event for every control.
Set the UpdateMode of your UserControls's UpdatePanels=Conditional.

For example in your UserControl's Codebehind:

Public Sub Update()
    'bind Data to your UpdatePanel's content f.e.:
    Me.Label1.Text = Date.Now.ToLongTimeString
    Me.UpdatePanel1.Update()
End Sub

And in your Mainpage:

Private myControls As New List(Of WebUserControl1)

Private Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
     For i As Int32 = 1 To 10
        Dim newControl As WebUserControl1= DirectCast(LoadControl("./WebUserControl1.ascx"), WebUserControl1)
        myControls.Add(newControl)
        MainPanel.Controls.Add(newControl)
     Next
End Sub

Protected Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    'in this example added dynamically
    For Each ctrl As WebUserControl1 In Me.myControls 
        ctrl.Update()
    Next
End Sub

In the UserControl's ascx-file:

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>             
    </ContentTemplate>
</asp:UpdatePanel>

In the Mainpage's aspx-file:

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
     <asp:Panel ID="MainPanel"  runat="server">
        <asp:Timer ID="Timer1" runat="server" Interval="1000"></asp:Timer>
     </asp:Panel>             
    </ContentTemplate>
</asp:UpdatePanel>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文