マスターページ
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs" Inherits="WebApplication1.Site1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate> <asp:Label Id="lblmaster" runat="server" Text="Label"></asp:Label>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"> </asp:ContentPlaceHolder>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
ASPXページ
<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="WebApplication1.WebForm2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="labelform" runat="server" Text="Label"></asp:Label>
<asp:Timer ID="Timer1" runat="server" ontick="Timer1_Tick" Interval="10">
</asp:Timer>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick"/>
</Triggers>
</asp:UpdatePanel>
</asp:Content>
ASPX ページの分離コード
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Timer1_Tick(object sender, EventArgs e)
{
labelform.Text = DateTime.Now.ToString();
// UpdatePanel1.Update();
Label lblmaster = this.Master.FindControl("lblmaster") as Label;
lblmaster.Text = DateTime.Now.ToString();
}
}
}
ノート :
両方の更新パネルの更新モードを「条件付き」に設定します
updatePanel2 に時間コントロールを追加
UpadatePanel2 内に AsynhronousTrigger を追加し、コントロール ID をタイマーに設定し、イベントを EventName としてチェックします。
コード ビハインドの timer_tick evert にコードを追加して確認してください。
ここで重要な点は、サーバーへの非同期呼び出しを実行し、ページの特定の部分のみを更新するために updatepane の更新モードを条件付きに設定し、トリガーでその特定の部分を更新するための条件を設定する必要があることです。
これがあなたを助けることを願っています
コーディングを続けてくれてありがとう........! :)