具有多个控件集合的 ASP.Net 容器控件

发布于 2024-09-04 06:18:13 字数 1813 浏览 2 评论 0原文

我一直在尝试创建一种特殊的字段集。它可以做各种奇妙的事情,但主要是崩溃和维持状态。此外,字段集的两个部分(图例中和其余部分)必须可用于后面的代码(以声明方式)。

使用页面或控件中的代码应如下所示:

<myTagPrefix:Fieldset>
 <myTagPrefix:Legend>[controls here should be available in codebehind]</myTagPrefix:Legend>
 <myTagPrefix:Content>[controls here should be available in codebehind]</myTagPrefix:Content>
</myTagPrefix:Fieldset>

或者

<myTagPrefix:Fieldset>
 <Legend>[controls here should be available in codebehind]</Legend>
 <Content>[controls here should be available in codebehind]</Content>
</myTagPrefix:Fieldset>

它将或多或少地生成以下 HTML(不包括神奇的折叠和状态维护代码):

<fieldset>
 <legend>[result of rendered legend controls]</legend>
 [result of rendered legend controls]
</fieldset>

我研究了一个模板化控件,公开了模板容器通过标记为“TemplateContainer”的属性,效果很好,只是后面的代码无法再访问模板中的控件。

我还研究了 继承容器控件(如面板),并重写了渲染方法开始和结束标记,这也很好,除了它只能包含一个控件集合,而此字段集控件应该有两个(图例中的控件和其余字段集中的控件)。这可以通过将图例的文本公开为字段集的属性来解决,但为了使事情变得复杂,文本并不是图例中唯一显示的内容。 (例如:也可以显示图像和按钮)。

当然,这个问题可以更抽象地看待,我基本上是在要求一个具有多个子控件集合的容器控件。

当我试图弄清楚要与什么进行比较时,该功能接近 多视图; MultiView 只能包含控件类型为“查看”,并且视图的控件在代码隐藏中可用。事实上,MultiView 不限制其子控件的数量和唯一性,而我的控件应该(最多一个图例和一个内容元素)是我可以忍受的......现在;)

有人知道吗MultiView 是如何构建的?有我忽略的技巧吗?任何帮助或建议将不胜感激。

I've been trying to create a special kind of fieldset. Which does all kind of fantastic things, but mainly collapse and maintain state. Also the two parts of the fieldset (in the legend, and in the rest) must be available to code behind (declaratively).

The code in the consuming page or control should look something like this:

<myTagPrefix:Fieldset>
 <myTagPrefix:Legend>[controls here should be available in codebehind]</myTagPrefix:Legend>
 <myTagPrefix:Content>[controls here should be available in codebehind]</myTagPrefix:Content>
</myTagPrefix:Fieldset>

Or

<myTagPrefix:Fieldset>
 <Legend>[controls here should be available in codebehind]</Legend>
 <Content>[controls here should be available in codebehind]</Content>
</myTagPrefix:Fieldset>

Which would produce more-or-less the following HTML (excluding the magic collapsing and state-maintaining code):

<fieldset>
 <legend>[result of rendered legend controls]</legend>
 [result of rendered legend controls]
</fieldset>

I've looked into a templated control, exposing template container via properties marked as 'TemplateContainer', which works nice, except for the fact that the code behind cannot access the controls in the template anymore.

I also looked into inheriting a container control like panel, and override the render methods for the begin- and end-tag, which is also nice, except for that it can contain only one control collection, while this fieldset control should have two (the controls in the legend and the controls in the rest fieldset). This could be overcome by exposing the text of the legend as a property of the fieldset, but to keep things complicated, text is not the only thing to be displayed in the legend. (for instance: images and buttons can be displayed too).

This question can be seen more abstractly of course, I'm basically asking for a container control with multiple child control collections.

When I tried to figure out what to compare this with, the functionality comes close to a MultiView; a MultiView can only contain controls of Type 'View', and the controls of a View are available in code-behind. The fact that a MultiView does not restrict the number and uniqueness of its childcontrols, and my control should (a maximum of one legend, and one content element) is something I could live with ... for now ;)

Does anyone have an idea how the MultiView was built? Is there a trick I'm overlooking? Any help or suggestion would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文