Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
147 views
in Technique[技术] by (71.8m points)

c# - ASP.NET Custom Controls - Composites

Summary

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!

  1. 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.
  2. 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.
  3. 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:

  • 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.

The Question(s)..

So, I admit, I am new to this so I could be way off-base with some of my points noted above..

  • Do you use Composites?
  • Do you have any neat tricks to control the HTML output?
  • Do you just say "to hell with it" and go ahead and create a custom rendered control?

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.

I look forward to your answers ^_^

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...