Get started with creating ASP.NET user controls – Part 1

“USER CONTROLS”. Have you heard the term before?? Lastly i heard this term when i was studying a course in .NET. After that i never cared to know about User Controls until i get into a job.

In Object oriented programming, Everything is encapsulated to exhibit “modularity”. Everything is wrapped up to make the code manageable.

I would like to give you a real time example. Consider that you are going to build a custom system. So
the first thing you will do is to sketch the configuration for the system like the processor is of 2.4 Ghz, RAM is of 4 GB, Hard Disk is of 1 TB etc..

Did you care about what type of capacitor or what type of components used in Motherboard? or What type of parts or components does the Hard disk has??? Even the Manufacturer never cared of what system the Hard disk is going to be used for. The only thing you concentrate is on the Capacity, Interface and the speed. The manufacturer cares of the other things like building the components, working, technologies etc.

The user control is similar to the hard disk. The User control developer never cares where it is going to used for except the Platform, Technology. If you build a control that to be used on ASP.NET, you can only use in ASP.NET and cannot be used in some other technologies. I think this will give you a rough idea about User Controls.

I would like to share my experience about using a “User Control”. While building an application, i was asked to create a “ToolBox” like placing four buttons on the top of the page like “Add New”, “Delete”, “Save”, “Back”.

The first thing i realized was this things are going to be used in all the pages in the application. This buttons are not normal buttons, they are image buttons. I really felt too lazy to place buttons inside a table, and adding images to the buttons in all the pages. You may think of copy and pasting. It is a good idea. But what happen if i want to change a image of a button or add a new button inside the toolbox.

I felt that this would be a right place to use a  “User control”. Because, if there is a change, i need to only change in the user control and not in all the pages. I need to change only once, it reflect on all the pages where i used this control.

In the next part, I’ll be explaining about how to build a simple user controls with Properties and Events.


Leave a Reply

Your email address will not be published. Required fields are marked *