【问题标题】:Literal Control text rendering doesn't work in Update Panel文字控制文本渲染在更新面板中不起作用
【发布时间】:2013-05-20 18:41:27
【问题描述】:

在我的 ASP.NET 应用程序中,我有更新面板和自定义服务器控件。

此自定义控件具有内部文字控件。我尝试以编程方式设置它的文本属性。但它不会呈现,因为字面量控制在更新面板中。

我该如何解决这个问题?非常感谢。

这是我的代码:

<asp:UpdatePanel runat="server" ID="updPanel">
<ContentTemplate>
    <st:AspGridViewTitlePanel runat="server" ID="GridTitle" Width="100%">                               
    </st:AspGridViewTitlePanel>     
</ContentTemplate>
</asp:UpdatePanel>

AspGridViewTitlePanel - 这是我的服务器控件。它有这样的代码:

this.myLiteralControl = new LiteralControl();
this.myLiteralControl.Text = "Some text";

【问题讨论】:

  • 请发布您的代码。

标签: asp.net updatepanel literals


【解决方案1】:
protected void page_load(object sender, args e) {
  if (!Page.IsPostBack) {
    LiteralControl myLiteralControl = new LiteralControl();
    myLiteralControl.Text = @"<span> MY TEXT </span>";
    UP1.ContentTemplate.Controls.Add(myLiteralControl);
  }
}

Adding controls dynamically to an UpdatePanel in ASP.NET AJAX

【讨论】:

  • 在我的例子中:updatepanel.ContentTemplateContainer.Controls.Add(literalName);
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-04
  • 2019-06-17
  • 2014-02-12
  • 2017-03-13
  • 2011-05-09
相关资源
最近更新 更多