Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ServerControl versus UserControl

Tags:

asp.net

I'd like to hear some reasons for using a ServerControl opposed to a UserControl. I've found that I probably overuse UserControls.

My list looks something like this:

Pro UserControl

  1. Easily modified. Need to add a class attribute to an element, hack it out in html.
  2. Quick and easy to create initial view. Everyone can write simple html right?

Pro ServerControl

  1. Performance. No html parsing.
  2. Flexibility. Control rendering down to a gnat's behind.
  3. Reusability. Compile it and stick it in the GAC for later use. Or, sell it.

Anything that I'm missing?

like image 575
Darthg8r Avatar asked Sep 24 '26 10:09

Darthg8r


2 Answers

The following two advantages of server controls come to mind:

  • support for inheritance (because the actual user control at runtime inherits from your code behind, you can't inherit from it anymore)
  • detailed control over the tag's parsing (should nested tags be treated as child controls or properties, etc.)
  • support for control adapters (declarative, e.g. in a .browsers file)
  • support for tag mapping (if you're making your own controls that's often very useful though)

However, user controls do have an additional edge because they're templated:

  • support for databinding expressions
like image 166
Ruben Avatar answered Sep 27 '26 09:09

Ruben


One other consideration is whether you want visual studio designer support at the time you're building the control or at the time you're using the control on the page. It really irks me that you only get one or the other, but not both.

like image 36
Joel Coehoorn Avatar answered Sep 27 '26 07:09

Joel Coehoorn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!