As a former VFP developer...it is actually MUCH easier in .NET once you understand the structure of .NET. Greg's sample is spot on...just create a class, then inherit whatever base class that you would like. You can then override base functionality (which is much better then VFP ever was in this area, especially as it relates to events). For example, if I inherit a TextBox and want to change the logic (or add to) of the TextChanged event I could do this:
Protected Overrides Sub OnTextChanged(ByVal sender As Object, ByVal e As EventArgs) MyBase.OnTextChanged(sender, e)
'-- Add your logic here (or above the base if that is what your require....You can also skip the base logic altogether ' if that is in fact what you are trying to accomplish. End SubEnd Class
This is no different for web than it is for Windows. The only difference is that you will want to create a class library that your web site or web application references to house all of your custom (or inherited) controls. Here is how you would subclass a web textbox:
Ok, I've tried that without any success. Does it have to be in it's own assembly to work? When I create the subclass for the textbox I can't find any way to put it on a webform and actually use it. This is where things are geting stuck. Once I have created the subclassed control how do I use it, since I'm guessing that I have the subclassed control now, but I can't put on anything and use it.
Once you create the class, make sure that your web application has a reference to the assembly that houses the class you created. You can also turn on the AutoPopulateToolbox option for it to show in your toolbox...or just type in the name of the namespace and class when defining the object.
To turn on the AutoPopulation of the toolbox click Tools->Options->Windows Forms Designer->General->AutoToolboxPopulate .
I know that it says "Windows Forms" but this populates the Web controls as well.
Just to clarify what I am going to try here, I do need to create a seperate assembly containing any subclassed controls I want to use and then I can reference them and use the controls? I think I can work with that. I have some other questions on whether I can do some things or not but I'll start another thread for that.
Yup...this is exactly what you should do. This is the very same thing that we do for all of our applications as well as our web applications. So just create a class library, add all of your subclassed controls, then you can use them instead of the standard controls. This is good programming standards...good job