asp.net/ajax-外部からトリガーするWebユーザー制御更新パネル
-
03-10-2019 - |
質問
UpdatePanelを使用してWebユーザーコントロールを持っています。私のメインページでは、それらのコントロールのうち3つのようになりました。次に、WebユーザーコントロールのupdatePanelsをトリガーするメインページにタイマーを用意したいと思います。
どうすればこれを管理できますか?
前もって感謝します。
解決
AjaxタイマーコントロールをUpdatePanelトリガーとして使用します
更新パネルの更新機能を呼び出すUserControlに更新機能を実装し、すべてのコントロールのTimertick-Eventのメインページから呼び出します。 usercontrolsのupdatePanels =条件付きのupdateModeを設定します。
たとえば、usercontrolのcodebehind:
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
USERCONTROLのASCXファイルで:
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
MainPageの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>
所属していません StackOverflow