2010-05-05 3 views

답변

1

Using the AJAX Timer Control as an UpdatePanel Trigger

자신의 업데이트-패널의 업데이트-함수를 호출하고 모든 제어를위한 TimerTick - 이벤트의 Mainpage에서 호출 당신의 UserControl에서 업데이트-기능을 구현합니다. UserControls의 UpdatePanels = Update의 UpdateMode를 설정하십시오. 당신의 Mainpage

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

그리고에서 : 해당 UserControl의 ASCX 파일에서

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 

:

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

Mainpage의 영문 파일에서 당신의 UserControl의 Codebehind가 예를 들어

:

<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> 
관련 문제