This is the site where I keep people up to date on my madden football league, College and Pro football, funny inncidents throughout the week, and also any and every funny things worth mentioning from the weekend.
To Be or not to be, that is the question.
Published on June 15, 2004 By King Punjabi In Work Reports

In attempts to find some a higher level of code reuse as far as user-defined controls are concerned, I turn to the asp.net custom controls.  These controls give the developer a way to encapsulate some commonly used "Stuff" over and over again promoting reusable code.

ahh yes reusability, the dream of every man and woman.  Of course we have seen it done in all languages and asp.net is definately no different and promotes it with Custom User Controls, and Custom Server Controls.

Custom User Control:

Background: Has the .ascx extension, and cannot be called via a url, but can make up the bulk of an asp.net page. 

Purpose: To encapsulate some commonly used HTML into an object such that it can be re-used across a site, or many sites for that matter and this Web user Control has a .ascx.vb class attached to it so the data can be database driven with ease.

Example: Lets say you want to display a box in the body of some page that displays the top 10 most recent skins posted by a particular user and lets also say that this bit of information will be used in many pages across a site or many sites. Well you can simply write the core html in the .ascx file, and within the .ascx.vb file, determine what author we have and what library we need to display, structure some query around it, and simply Databind the result to our web user control and that's it.  And the beauty of this control is that you can plug in/plug out this control anywhere in the page, you just simply need to write some structured html to tell it to stretch this way or that, span this way or that, skin yourself in this way or that.

Of course this type of functionality has always been available in previous languages with Doing Includes in different sections of the page, but asp.net, they make it much more simple and give the developer much more control on each web user control because they are simply objects that take on an object oriented interface( does that sound right?? ) so true data encapsulation is met.  With The classic way of doing things, you would be essentially be interacting with many sets of global variables from each Include file, and many other headaches that are not worth discussing at this time because i'm getting tired of typing!

Custom Server Controls

Background: Most or all server side controls such as a textbox, dropdownlist, Repeater, Datalist, Datagrid, etc all derive from System.Web.UI.WebControls.  Custom Server Controls can be created to act in many ways the same as a Web User Control in that it displays a set of data and can be re-used across many sites but to a higher degree which i will explain in some other article.

Purpose: To create some custom control with detailed behavior that you decide.  So for instance, lets take that same example of the the top 10 most recent skins posted by a particular user.  We can re-create this scenario with a custom server control, but with more control over what and how the data is displayed.  The drawback with Web User Controls is that the HTML Design of the control is static, meaning you give it a defined look and feel and that's it. But with a custom server control all the design logic can be implemented dynamically.  I will explain some other time on how this is done.

This is only the tip of the ice berg of course, i will have plenty more to come with examples of how, where, what, and why i am using server controls and user controls.

5/17/04 Work Report


Comments
on Jun 15, 2004
Sounds interesting, will be waiting for further articles
on Jul 01, 2004
on Jul 14, 2004
sdfg
on Jul 14, 2004
Well, I know now I need to get into .NET. i was told about VB.NET and I liked it (combining C++, Java and other code and being able to link it up with different database types is great... If I remember what I was told correctly). So I decided I would learn it and use it for myself to get a job or make myself something.
on Jul 21, 2004
asdfasdf
on Jul 24, 2004
asdfasd

asdfasf
on Jul 24, 2004
blah