Question

This is one question about two things: When do I use [a] user controls, [b] interfaces? Or, given all the possibilities what would be the optimum use of the said items.

Why do I ask?

UserControl: I attempted to create a website with one ASPX page and multiple ASCX pages -- there's a master + transaction requirement -- but after struggling with the ASCX pages I now have to redo it in ASPX as the ASCX pages were getting pretty complicated -- multiple inputs, data elements, et. al. (about 500 data elements scattered over 11 ascx pages). So the question is -- What is the best place to use an ASCX page?

Interface: Same scenario above -- to control data on the pages (save, discard, update, et. al.) I had used controls on the ASPX page; which failed terribly, so I tried interfaces and I am not really making much of a headway there either, so I am back to the very basic method of using repetitive controls on ALL ASPX pages... needless to say that is tedious.

I would like to know what am I doing wrong, conceptually speaking!

Was it helpful?

Solution

You seem slightly confused between interfaces and User Controls which are totally different from each other. There are many articles that describe each of them in detail. But I would tell you how I use them

User Controls: I use User Controls mainly for the User interface encapsulation. for instance if I have some text boxes, labels, few dropdowns and panels, I would have to write code to handle them for instance I have a drop down and based on its values I have to enable or disable some functionality. I also have to perform some validation. I can do that in the webpage but its better that I encapsulate them in a user control.

a) my code would not clutter my web page code, b) its encapsulated in a control c) the functions of the control would collectively manipulate the controls and their code for instance.

The code in my web page would be very clean and easier to read also overall the code is easier to maintain. also with the user controls it is possible to use the same functionality in many pages without writing the code again or even copying and pasting it.

Interfaces: 1I use interfaces in special cases. for instance there is a requirement where a control has to interact with the page it is contained in. Usually programmers typecast the page to the actual class and use it. what I do is that I create 2 interfaces. one would be the one that page implements and the other is the one that the control implements. through these interfaces they would interact with each other and the dependency is not hardcoded. that means any control that implements the interface that the page requires would implement it and the page can start interacting with the control. technically C++ implements the multiple inheritance and many modern languages do not allow multiple inheritance so to solve the issue they have these interfaces since a class can implement any number of interfaces thus giving the illusion of multiple inheritance.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top