How To Create and Inherit From A Base Web User Control

This is a tricky situation.The kind that we turn to runestones to unravel.

Problem – You can create a base User Control in a Windows Form project. Then, you can create another User Control that is inherited from the first quite easily by choosing Add New Item/Inherited User Control from your Solution Explorer (right click your project to get this menu). You cannot do the same for a Web User Control.

Now, why do you want to do this? Well, you’ll want to do this for the same reason you’ll want to create a base class in any other situation – you may wish to embed commonly used attributes and methods into the base class. Then, when you create sub-classes that inherit from it, you only need to write codes for pieces of specialized work that differ from the common functionalities.

Solution – The solution is actually quite simple. Follow these steps –

  1. Create your base class in the App_Code folder (right-click App_Code folder, select to create a Class)
  2. Ensure that your base class is implemented inside a namespace (begin the class declaration with a namespace.. statement and end it with an ..end namespace statement)
  3. Create your sub class and inherit it from the base class (assuming that your sub-class is a visible Web User Control for a DotNetNuke module, right-click on the DesktopModules folder, then select to create a new Web User Control. After it has opened, modify the Class declaration code for the new We User Control by changing the … inherits clause).

I got this solution from a response to a question.


One thought on “How To Create and Inherit From A Base Web User Control”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s