1
我有一个带有更新面板的Web用户控件。在我的主页上,我收到了3个控件。现在我想在主页面上有一个定时器,它会触发Web用户控件中的更新面板。ASP.NET/AJAX--从外部触发Web用户控制更新面板
我该如何管理?
在此先感谢。
我有一个带有更新面板的Web用户控件。在我的主页上,我收到了3个控件。现在我想在主页面上有一个定时器,它会触发Web用户控件中的更新面板。ASP.NET/AJAX--从外部触发Web用户控制更新面板
我该如何管理?
在此先感谢。
Using the AJAX Timer Control as an UpdatePanel Trigger
实现你的用户控件这就要求他们更新-面板的更新,功能和从TimerTick-事件的网主页的每个控制称它为更新-功能。 设置UserControls的UpdatePanels = Conditional的UpdateMode。
例如,在你的用户控件的代码隐藏:
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>