.NET custom/user controls, web services and httphandlers

questions on these 4 .NET topics: custom controls, user controls, web services, httphandlers.

pleaes answer all:

1. can't they all, or several of them, be used to basically perform the same task?
2. what really makes them different/unique besides the obvious?
3. what are some simple "real-world" ideas/examples for each one that would illustrate:

a. how they are different, if at all.
b. how they can be used together to perform some kind of simple web solution.

if possible, examples from your own experience with using them would be ideal.

thank you!
Who is Participating?
naveenkohliConnect With a Mentor Commented:
all four of these are totally diferent creatures.

UserControl - It is a custom control but it inherits a lot of attributes from base classes. The example will be a composite control. Where you derive a control like LoginBox. This box will host 2 text and 2 label control and a button. And you can use this user control on your pages as a one single enity. The documentation has an example for this control.

Custom Control - Its a control that is derived from Control class. And does not inherit whole lot of attributes (Properties, Events, Method) implementatios from base classes as compared to UserControl. The big difference is that you will be responsible for emitting the HTML stream for this control. You will not be aggregating any existing control. Nothing stops you from that, but the whole idea behind a Custom Control is to develop a control from scratch. Take a look at the folloing link. Its custom "UpDown" control. It emit its own HTML stream in Render method.

HtppHandlers - They are equivalent of ISAPI extensions. They provide you low level access to actual HTTP request and response. They are utilized for processing the requests before they get to the ASP.Net page processing. All the operations in ASP.Net framework happens through HttpHAndlers. Take a look at Machine.config file. You will find a whole bunch of HttpHAndlers defined there. Here are couple of examples SessionStateSectionHandler, CompilationConfigurationHandler, etc. You can create an object implementing IHttpHandler interface. Then you register this handler with framework through web.config file. What will happen is that your handler will get chance to process the request in ProcessRequest method. There you can modify the request. For example in FormAuthentication, the handlers process the request and check presence of authentication tickets. Based on that tests, the user is redirected to appropriate pages.

WebServices - I don't know how should I describe them in short. They are a topic in itself. Consider it like a service provided over the internet. For example I have a service that processes image geenration requests. The caller sends me the data for rendering images in XML string format. My web service (ASP.Net , asmx file) recieves the request and processes the input information, renders the image and sends the output stream to caller. Its like invoking a remote component over the internet. The difference is that the service publishes it capabilities throough WSDL files instead of a typelib or IDL file incase of COM object. I think documentation will give you more insight into this.

So you can see that all 4 creatures a totaly different used for diferent purposes.


WebServices - These are a
loyaliserAuthor Commented:

i understand the UserControl perspective... the idea of making web sites modular - just like the IBuySpy.com sample web site. very neat and clear usage.

clearly, UserControls are being used because it is a matter of new design structure for web sites using ASP.NET. that i understand.

CustomControls and HttpHandlers:

when it comes to CustomControls and custom HttpHandlers, i am at a loss as to what "the motivating factors" are behind using them?

that is my main confusion... when do i know that i need to, or should, use them?

Web Services:

ok... the idea of some internet-based service that returns data to user/server based on some input it receives makes sense... like a news web service that consumes date ranges, and produces news articles in XML format within those date ranges.

but question with this is: can't the same effect be created using Custom or UserControls?

if so, how do i know which of the 3 to use?

thank you.
As I mentioned earlier, you will use Custom Controls for purposes where the existing web server controls don't serve the puspose. The example I gave of UpDownControls. There is no control in library that will provide this functionality. So the only option you have in that case is develop your own control. Conside them like Owner Drawn controls in MFC where you have to do all the painting your self. Its the same way. In custom controls you will do all the redenring. Another example of custom control is Tree control. There is a web control that serves the purpose. But that onlt works for IE. So for browser independent implementation, you will have to create your own Custom tree view control. And similarly creating Menu controls.

HttpHandlers have nothing to do with server controls. Normally you don't require to implement HttpModules. Like you very rarely create ISAPI extensions. Here is an example from documentation.
           <add verb="*" path="*.jpg"
                type="JpegFileHandler,httpruntime" />
This configuration indicates that if anybody requests a file with extension .jpg, the JpegFileHandler HttpHandler should process the request. And in your processRequest of this httphandler, you can pre-process the information. So If your application plicy does not allow some user to get JPG file, you can end the response there and don't let it get the file.

Then to go a level lower, you can implement HttpModules. They are equivalent to ISAPI filters.

On the same note, WebService have nothing to do with controls.

UserControls are pages initeself. You can assemble other server controls in the user control to build a module so that you can provide uniform look and feel to the site. For example building Header, Footer, TopMenu, LeftMenu, MainBody templates as UserControls. And then on each page you can load these user controls to have same look.

Use CustomControls to enhance functionlity of exsiting server control or develop something that does not exist.

loyaliserAuthor Commented:
good thanks... it is making more sense now...

the techicals are easy to grasp... just needed to get the idea/logic behind these things down, so i'll know what to do with them when the time comes.

loyaliserAuthor Commented:
good thanks... it is making more sense now...

the techicals are easy to grasp... just needed to get the idea/logic behind these things down, so i'll know what to do with them when the time comes.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.