Update()
コントロールの値を希望する値に設定し、UpdatePanelのメソッドを呼び出して、コード ビハインド ファイルから更新しようとしているコントロールを含む ASP.Net Update Panel があります。
Update() メソッドを呼び出すには、UpdateMode プロパティを条件付きに設定する必要があることを知っているので、これを実行しましたが、関係なく次のエラーが発生します。
UpdateMode が Conditional に設定されている場合、Update メソッドは ID が「UpdatePanel1」の UpdatePanel でのみ呼び出すことができます。
[マイ プロパティ] ボックスは次のようになります。
私のコードは次のようになります。
using System;
using System.Timers;
namespace WebApplication2
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
var myTimer = new System.Timers.Timer();
myTimer.Interval = 1000;
myTimer.Elapsed += new ElapsedEventHandler(myTimer_Elapsed);
myTimer.Start();
}
void myTimer_Elapsed(object sender, ElapsedEventArgs e)
{
var newGUID = Guid.NewGuid().ToString();
Label1.Text = newGUID;
UpdatePanel1.Update();
}
}
}
私のフォームは次のようになります。
私のマークアップは以下のとおりです。
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication2.WebForm1" %>
<!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>
<style type="text/css">
#form1
{
text-align: center;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" style="text-align: center" Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
なぜこれが機能しないのですか?
ありがとう