问题描述
大家好,
好的,使用自定义控件进一步探索我的冒险......
Hi All,
OK, further into my adventures with custom controls...
总之,这里是我学习了三个主要的类".的自定义控件.如有错误请随时纠正我!
In summary, here is that I have learned of three main "classes" of custom controls. Please feel free to correct me if any of this is wrong!
- UserControls - 继承自 UserControl 并包含在 ASCX 文件中.它们的功能非常有限,但可以通过设计师支持快速轻松地获得一些 UI 通用性.
- 自定义复合控件 - 这些控件继承自 WebControl,您可以在 CreateChildControls 方法中将预先存在的控件添加到控件中.这提供了极大的灵活性,但在没有额外编码的情况下缺乏设计者支持.它们具有高度可移植性,因为它们可以编译成 DLL.
- 自定义呈现控件 - 与自定义复合控件类似,这些控件被添加到 Web 控件库项目中.控件的呈现完全由程序员通过重写 Render 方法来控制.
- UserControls - Which inherit from UserControl and are contained within an ASCX file. These are pretty limited in what they can do, but are a quick and light way to get some UI commonality with designer support.
- Custom Composite Controls - These are controls that inherit from WebControl where you add pre-existing controls to the control within the CreateChildControls method. This provides great flexibility, but lack of designer support without additional coding. They are highly portable though since they can be compiled into a DLL.
- Custom Rendered Controls - Similar to Custom Composite Controls, these are added to a Web Control Library project. The rendering of the control is completely controlled by the programmer by overriding the Render method.
我的想法..
好的,所以在玩自定义合成时,我发现了以下内容:
My Thoughts..
OK, so while playing with custom composites, I found the following:
- 您几乎/无法控制 HTML 输出,因此难以调试".
- CreateChildControls(和后续方法)可能会因无处不在的 Controls.Add(myControl) 而变得非常忙碌.
- 我发现渲染表格(无论是布局还是内容)都非常尴尬.
- You have little/no control over the HTML output making it difficult to "debug".
- The CreateChildControls (and subsequent methods) can get real busy with Controls.Add(myControl) everywhere.
- I found rendering tables (be it for layout or content) to be considerably awkward.
所以,我承认,我是新手,所以我可能对上面提到的一些观点有些偏离基础......
So, I admit, I am new to this so I could be way off-base with some of my points noted above..
- 您使用复合材料吗?
- 你有什么巧妙的技巧来控制 HTML 输出吗?
- 你只是说见鬼去吧"吗?并继续创建一个自定义呈现的控件?
我很想牢记这一点,因为我知道良好的控件开发可以在多大程度上缩短整体开发时间.
Its something I am keen to get really firm in my mind since I know how much good control development can cut overall development time.
期待你的回答^_^
推荐答案
我说继续自定义渲染控件.我发现在大多数情况下,复合可以更容易地在 UserControl 中完成和使用,但除此之外,您需要有更好程度的控制(无意中的双关语)才能获得自己的渲染策略.
I say go ahead with the custom rendered control. I find that in most cases the composite can be easier done and used in a UserControl, but anything beyond that and you'd need to have a finer degree of control (pun unintended) to merit your own rendering strategy.
可能有足够简单的控件值得组合(例如,文本框与基于 javascript/dhtml 的日期选择器相结合),但除此之外,看起来自定义呈现的控件是可行的方法.
There maybe controls that are simple enough to merit a composite (e.g., a textbox combined with a javascript/dhtml based datepicker, for example) but beyond that one example, it looks like custom rendered controls are the way to go.
这篇关于ASP.NET 自定义控件 - 组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!