我有一个非常简单的用户控件,如下所示:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="wfWindow.ascx.cs" Inherits="webfanatix.co.za.wfWindow" %>
<div>Just a test...[x]</div>
后面有这段代码:
[ParseChildren(false)]
[PersistChildren(true)]
public partial class wfWindow : System.Web.UI.UserControl
{
protected override void Render(HtmlTextWriter writer)
{
RenderChildren(writer);
}
}
其用法如下所示:
<wf:wfWindow runat="server">This content should go where [x] is.</wf:wfWindow>
我不是 ASP.NET 专业人士,那么如何让内容准确呈现在我的用户控件中出现 [x] 的位置?
RenderChildren 正在呈现我的内容,但它仅附加到 UserControl 输出的末尾。我需要它去并坐在 [x] 标记的位置。
提前致谢!
最佳答案
将 [X] 更改为它自己的控件,可以容纳其他控件,例如占位符或面板。
然后覆盖AddParsedSubObject() .这个的默认实现只是将控件添加到 usercontrol 的 Controls 集合中——这意味着它们被添加到最后。覆盖它以将它们添加到您的占位符。
protected override void AddParsedSubObject(Object obj)
{
PanelWhereXIs.Add(obj);
}
关于c# - 如何在特定位置呈现用户控件子项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2024320/