c# - 更新母版页计时器上的内容页控件 TIck

标签 c# asp.net

我有一个母版页

<asp:Timer ID="masterTimer" runat="server" Interval="1000" OnTick="masterTimer_Tick"/>
        <asp:UpdatePanel runat="server" ID="time" UpdateMode="Always" ChildrenAsTriggers="True">
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="masterTimer" EventName="Tick"/>
            </Triggers>
            <ContentTemplate>
                <asp:Label runat="server" ID="lblTime"></asp:Label>
            </ContentTemplate>
        </asp:UpdatePanel>

在代码后面我有简单的

protected void masterTimer_Tick(object sender, EventArgs e)
        {
            this.lblTime.Text = DateTime.Now.ToString("ddd MMM dd yyyy h:mm:ss tt");
        }

在内容页面中我有

Dictionary<Guid, string> data = dataClass.DataDictionary();

然后我在默认页面(内容页面)中创建标签类型的动态服务器控件。服务器控件具有 Text 属性。现在我的问题是,在每个刻度上,它确实读取了正确的数据,这意味着数据字典包含更新的数据,并且它确实将其分配给标签文本属性,但它不显示更新的文本。

我正在像这样创建我的 CustomeLabel

    CustomLabel newLabel = new CustomLabel
    {
        Text          = "Label",            
        Width         = 200,
        Height        = 150,
    };
    this.Controls.Add(newLabel);

下面是从 LinkLabel 派生的 CustomLabel 类,它具有以下属性

public string Text { get; set; }
public int Width { get; set; }
public int Height { get; set; }

readonly LinkButton Label              = new LinkButton();

protected override void OnLoad(EventArgs e)
{
  Label.Text = Text;
}

protected override void Render(HtmlTextWriter output)
{
  base.Render(output);
}

如果有人告诉我我需要做什么,我将不胜感激

最佳答案

这可能适合你:

子页面:

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="ChildPage.aspx.cs" Inherits="ChildPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">

    <asp:UpdatePanel ID="MyUpdatePanel" runat="server">
        <ContentTemplate>
            <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
        </ContentTemplate>

    </asp:UpdatePanel>


</asp:Content>


public partial class ChildPage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Label newLabel = new Label
        {
            Text = "Label",
            Width = 200,
            Height = 150,
        };
        newLabel.Text = "Label: " + DateTime.Now.ToString();

        PlaceHolder1.Controls.Add(newLabel);       
    }
}

关于c# - 更新母版页计时器上的内容页控件 TIck,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30127595/

相关文章:

c# - UWP Commandbar 到右侧

c# - 如何通过异步方法有效地更新 UI?

C# => 在这种特殊情况下,带有参数的 Lambda 表达式似乎过于流畅/毫无意义

c# - 如何创建不需要管理员访问权限的 Windows 安装程序 MSI

asp.net - IIS进行ASP.NET调试超时

c# - 没有扩展名时 Application_BeginRequest 不触发

c# - 如何反序列化包含分隔 JSON 的 JSON?

asp.net - ConnectionStrings 的 ServiceDefinition.csdef 和 Web.config 有什么区别?

c# - 如何在应用程序加载时仅在 ASP.net MVC 中运行一次方法而不从 Application_Start() 调用它

c# - 我应该如何在管道中引用 IHttpModule 实例?