简体   繁体   English

自定义Web控件。 如何呈现子控件

[英]Custom web control. how to render child controls

I'm trying emulate the IE Webcontrols Pageview system. 我正在尝试模拟IE Webcontrols Pageview系统。

Basically I have 基本上我有

<c:Multipage > <c:pageview > <c:Multipage > <c:pageview >

[Block of ASP.NET / HTML] [ASP.NET/HTML的块]

</c:pageview > (More pageviews) </c:Multipage > </c:pageview >(更多综合浏览量) </c:Multipage >

And I want to simply render the inner text of the pageview. 我想简单地呈现综合浏览量的内部文本。

I've tried 我试过了

protected override void AddParsedSubObject(object obj) { ... ControlList.Add((Control)obj); 受保护的重写void AddParsedSubObject(object obj){... ControlList.Add((Control)obj); ... } ...}

and

Render(HtmlTextWriter output) { ... foreach (Control c in ControlList) c.RenderControl(); Render(HtmlTextWriter输出){... foreach(ControlList中的控件c)c.RenderControl(); ... } ...}

It seems to render simple things but any more complex set ups it makes mistakes on. 它看起来可以渲染简单的东西,但是任何更复杂的设置都会出错。 I don't think this is the way to do it at all. 我认为这根本不是做到这一点的方法。 I'm having difficulty finding out how I am supposed to be able to just render this. 我很难找出应该如何渲染此图像。 And whether I should treat it as text or child controls 以及我应该将其视为文本控件还是子控件

You shouldn't need to explicity call Render. 您不需要显式调用Render。 If the control is part of your page's control tree, it will get rendered. 如果控件是页面控件树的一部分,它将被呈现。

It generally depends on whether or not you are display effectively read-only information or control information that would require view-state information. 通常取决于您是否显示有效的只读信息或需要查看状态信息的控制信息。 You can output raw HTML if it's read-only just fine but if it contains controls and requires view-state interaction then you'll want to create actual control objects and insert them into the containing object in the code behind. 如果原始HTML只读就可以了,但是如果它包含控件并且需要视图状态交互,则可以输出原始HTML,那么您将需要创建实际的控件对象并将其插入到后面的代码中的包含对象中。

It really depends on your specific situation, but it sounds like you could just output raw html into a generic DIV control or something, without knowing the specifics though it's a little tough to point you one way or the other. 这实际上取决于您的具体情况,但听起来您可以将原始html输出到通用DIV控件或其他内容中,而无需了解具体细节,尽管很难以一种或另一种方式指向您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM