Null Dates in Webforms, How?


Author
Message
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
You just create a class that is named whatever you like and inherit that class from the control you are sub classing:



' VB

Public Class MyTextbox

Inherits Microfour.StrataFrame.UI.Windows.Forms.Textbox

' code...

End Class



// C#

class MyTextbox : Microfour.StrataFrame.UI.Windows.Forms.TextBox {

// code...

}




This will then available in the toolbox under the project you put it in (each project that has controls, user controls or components will be a heading in the toolbox).
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Sometimes I wonder why I'm doing this, as subclassing a control like this was so easy to do in VFP.

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:

Public Class MyTextBox
    Inherits MicroFour.StrataFrame.UI.Windows.Forms.TextBox

    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 Sub
End Class


Cyrus Welch
Cyrus Welch
StrataFrame Beginner (38 reputation)StrataFrame Beginner (38 reputation)StrataFrame Beginner (38 reputation)StrataFrame Beginner (38 reputation)StrataFrame Beginner (38 reputation)StrataFrame Beginner (38 reputation)StrataFrame Beginner (38 reputation)StrataFrame Beginner (38 reputation)StrataFrame Beginner (38 reputation)
Group: Forum Members
Posts: 20, Visits: 82
This is all well and good, but all the examples seem to be for windows forms and don't seem to work for webforms.  All I want to do it subclass the control and be able to place it in my webform in place of the normal control.  I can't seem to do anything with a control created this way.  Am I missing something or is VS2005 broken on both my desktop and laptop?
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Cyrus,

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:

Public Class MyWebTextBox
    Inherits MicroFour.StrataFrame.UI.Web.TextBox
    Protected Overrides Sub OnTextChanged(ByVal e As System.EventArgs)
        MyBase.OnTextChanged(e)
    End Sub
End Class

Cyrus Welch
Cyrus Welch
StrataFrame Beginner (38 reputation)StrataFrame Beginner (38 reputation)StrataFrame Beginner (38 reputation)StrataFrame Beginner (38 reputation)StrataFrame Beginner (38 reputation)StrataFrame Beginner (38 reputation)StrataFrame Beginner (38 reputation)StrataFrame Beginner (38 reputation)StrataFrame Beginner (38 reputation)
Group: Forum Members
Posts: 20, Visits: 82
Trent L. Taylor (01/31/2008)
Cyrus,

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:

Public Class MyWebTextBox
    Inherits MicroFour.StrataFrame.UI.Web.TextBox
    Protected Overrides Sub OnTextChanged(ByVal e As System.EventArgs)
        MyBase.OnTextChanged(e)
    End Sub
End Class

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.

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Cyrus,

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.

Cyrus Welch
Cyrus Welch
StrataFrame Beginner (38 reputation)StrataFrame Beginner (38 reputation)StrataFrame Beginner (38 reputation)StrataFrame Beginner (38 reputation)StrataFrame Beginner (38 reputation)StrataFrame Beginner (38 reputation)StrataFrame Beginner (38 reputation)StrataFrame Beginner (38 reputation)StrataFrame Beginner (38 reputation)
Group: Forum Members
Posts: 20, Visits: 82
Trent L. Taylor (02/05/2008)
Cyrus,

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.

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
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?

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 Smile

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search