Moving a Sub from Derived Class to Base

Hello all,

 Thank you for reading this.

I have a set of custom controls that all inherit from a base class and implement an interface.


Base Class

    Public MustInherit Class InputControlBase
        Inherits System.Web.UI.UserControl



Imports Microsoft.VisualBasic
Namespace MyNamespace

    ''' <summary>
    ''' Indicates class is to be used as an input control
    ''' </summary>
    ''' <remarks></remarks>
    Public Interface IInputControl

    End Interface

Derived Class (Custom Control)


 Partial Class MyInputControl
    Inherits MyInputControlBase
    Implements IInputControl

    Protected Overrides Sub PopulateMenu() Implements MyNamespace.IInputControl.PopulateMenu
        Dim oMenus As New myMenus
        oMenus.LoadSearchMenus(MyNamesapce.CategoryTradeType.Trades, Me.drpOptions)
        Me.drpOptions.Items.Insert(0, New ListItem(sDefaultSelectMessage, String.Empty))
    End Sub

End Class


Now I want to move the Sub PopulateMenu into my base class since the functionality is the same and needs isolating but I am having problems doing this.  How do I declare an object and code in my base class that can populate the control in my derived classes?  I tried creating a dropdownlist called drpOptions in the base class and returning it but when I created it in my derived classes I got problems informing me to declare it as Shadows but couldn't get it to work properly.  There were nullreferenceexception(s) being thrown in routines that attempt to access the dropdownlist item.

 I think the main problem is that my base class doesn't have a form attached (it resides in my App_Code folder) and isn't declared Partial.  I think I need someone to point me in the right direction for moving Page objects to a base class without causing null reference exceptions.

 Any help would be greatly appreciated.



George-Louis de Buffon, Mathematician, the French Mathematician of Buffon's Needle fame - once said, "Genius is nothing but a great aptitude for patience" - so please take your time.
4/26/2009 6:48:30 PM 3498 articles. 0 followers. Follow

2 Replies

Similar Articles

[PageSpeed] 16

What you can do is make your function take in the dropdownlist you're trying to populate by reference (byref), then you can use this on any page for any dropdown name. Something like:


Protected Sub PopulateMenu(byref dd as DropDownList) Implements MyNamespace.IInputControl.PopulateMenu
     Dim oMenus As New myMenus
     oMenus.LoadSearchMenus(MyNamesapce.CategoryTradeType.Trades, dd)
     dd.Items.Insert(0, New ListItem(sDefaultSelectMessage, String.Empty))
End Sub 


Then you can call it from your pages PopulateMenu(drpOptions) and that'll do what you want.

Hopefully that'll work for you


4/26/2009 7:14:29 PM


Ah! So simple but then the most beautiful solutions often are. Well done -marked as answer



Big Smile 

George-Louis de Buffon, Mathematician, the French Mathematician of Buffon's Needle fame - once said, "Genius is nothing but a great aptitude for patience" - so please take your time.
4/28/2009 7:18:28 PM

Similar Artilces:

Best practice for custom control that can switch between objects derived from the same base class
I currently work for a company that has a WebUI for our product. At some point a class was made to draw differant kinds of graphs. This class had an ENUM that switched between the differant types(Bar, line, pie, etc). To me it seems like it would be better to make an Abstract base class and a differant class for each of the types rather then using a switch, however, this would require us to change ALL of the pages to hide and show differant controls based on the selected bar type.  What is typically the best practice for this kind of a situation, I had the idea of creating a prox...

Custom Server Control - Moving within the VS.Net Designer
Hi, I have created a custom server control that inherits from System.Web.UI.Control. I would like my end users to be able to drag and move the server control in the VS.Net IDE. I presume I have to expose the left/top style properties but can't find anything in the documentation or via google. Any pointers, links or code would be great :) R Hmmm, Inherit from System.Web.UI.WebControls.WebControl or just use the default Create Web Control project in the .Net IDE Can't believe I spent 1 hour looking for this :) Any element can be movable in VS.NET. What it really does is ...

Usercontrol vs Custom Server Controls, Any need for Custom Server Controls
Hello I'm new to ASP.Net so this is probably a stupid question but, is there any need to create customer server controls now that you can pre-compile usercontrols into a dll and thus easily share between applications? This blog post from David Ebb describes how to do it and the restrictions he note don't seem that bad (other than being able to embed resources such as images in the dll). His article desribes the techniques for ASP.Net 2.0 and he suggests that there will be further improvements in .Net 3.5 in this ar...

Problem Extending Class in Class Library project with WebConrol class for creating Custom Server Control.
I want to create a custim sevrer control. When I add a class and place it in the BIN directen I add a am able to extend the class with either the Control or WebControl class. But when I add a ClassLibrary project to my ASP.NET project, then I am not able to extend the class with either the Control or WebControl class. I am not able to use the System.Web.UI.WebControls. How to extend the the Class Library project class with either the Control or WebControl class?-----------------------------------------------Please click Mark as Answer if this helped. in your class library p...

Custom Server Control Vs Web Parts, Any need for Custom Server Control
Hello I've just posted a similar question on why you need server controls when you can pre-compile usercontrols and redistribute them. I've seen lots of (usercontrol vs web part) but not much on web part vs custom server control. According to the MSDN site you can put web parts onto a normal page outside of a web part zone and they behave just like custom server controls. So, if you are creating a bunch of controls for redistribution to customer sites and/or SharePoint sites why don't you just create Web Par...

problems listenening to events on a custom server control from another custom server control
 Hi all,I am having problems listening to events on one of custom server controls(AddBookmark) from another custom server control(BookmarkList). The listener or the BookmarkList control has a property that can be set to the AddBookmark control (string at design but the reference is obtained at run-time). I am able to get a reference to the AddBookmark control and add a listener to it on the BookmarkList control on the OnPrender of BookmarkList. But the problem is that when the events on AddBookmark gets fired, the listener added from the BookmarkList is no longer present and the listene...

Creating Custom Web Controls that Inherit from a Custom Base Class
Hi there,I have some existencial doubts, and hopefully someone can help me out with what I want to achieve.I need to create several custom web controls that share some common properties and methods. In nature, they are basically extensions to existing web controls like TextBox, DropDownList, etc., but with some extre properties: Options and Defaults. Basically what I need to do is to be able to handle this custom web controls in this way:  foreach(CustomBaseControl bc in ControlCollection) { bc.Options = yada yada; bc. Defaults = yada yada; } I don't want to go thr...

Creating .Net custom server controls and .Net pages programatically
Thanks a lot for reading this and greatly appreciate your inputs I am writing a webinterface that lets users configure options that'll create an interface for them and generete the webpage. So I am having to programattically create custom server controls and .Net page with code behind to support the functionality. Are there APIs in the .NET SDK that let you do this. Any pointers would be greatly helpful Thanks a lot Sathya Controls on the fly? Or Create code on the fly? I think it is the latter so here we go - look at the following namespaces: * System.Reflection.Emit - gen...

Custom Server Control Made of Custom Controls?
I'm giving myself a crash course in custom server controls, and I have a quick general question. Can I have a custom server control that is composed of other server controls I created. I'm pretty sure the answer is yes, but I want to be positive. Yes Shows how to combine existing controls into a new control using class composition. -ron Thanks! ASP.NET so rocks! Making page components extensible objects is such a great idea! I love it....

How can one call a custom server control DLL like a custom class library DLL
All -- How can one call a custom server control DLL like a custom class library DLL? Please help. I think that I am missing something simple? Or, maybe I am trying to do something impossible? Or, maybe something else? I have a custom server control DLL that I built, with a UI, etc, called... (A). App_Web_teamthemeselectorwebcontrol.ascx.cdcab7d2.dll ...and it works fine. I register my custom server control DLL on an ASPX page like this... (B). <%@ register tagprefix="team" namespace="Team.WebControls" assembly="App_Web_teamthemeselectorwebcontrol.a...

Custom Server Controls and SiteMap class
I have a custom control in which I am using the SiteMap class to build a menu. It runs perfectly and outputs exactly what I would expect. However, when I drag my control from the Toolbox into VS2005 Design View, I receive the error: The provider 'AspNetXmlSiteMapProvider' specified for thedefaultProvider does not exist in the providers collection." When I place code into my control to output the name of the provider being used, it outputs "AspNetXmlSiteMapProvider" and the control still works, so it is obviously finding the correct SiteMapProvider. Anybody have any ...

how to have both server controls and html controls rendered in a custom control?
I have a custom control in which there is an html text box.when you click on it , a div containing a table is appeared and according to what you select in that table a text is set to the text box. It works fine but the problem is: as the text box is an html element it doesn't have viewstate and when a post back occures in the page its value disappeares.I tried a hidden field to keep its value.again there is another problem : I put this custom control in a usercontrol and put the usercontrol in a multiview and by clicking on a button this view is selected and by clicking another bu...

Deriving a control from a base class declared MustInherit
I've heard this problem discussed before : basically i have a base class ################## code ################## Public MustInherit Class ControlBase Inherits System.Web.UI.UserControl End Class ################## And i try to derive my user control from it: ################## code ################## Public Class Control Inherits ControlBase #Region " Web Form Designer Generated Code " 'This call is required by the Web Form Designer. <System.Dia...

Building .NET Custom Server Controls and distribution
Can anyone tell me the best practice for distributing custom controls or controls that have been developed from inheriting server controls? I am curious how other companies support a custom library of objects developed by developers within an enterprise. At my company we follow the naming standards put forth by Microsoft: CompanyName.AppName.LayerName Example: Say I developed a Drop Down List that is used to display every year from 2004 to DateTime.Now in ascending order from inheriting the Web Server Control Drop Down List.  After a committee of other developers have tested and app...

Web resources about - Moving a Sub from Derived Class to Base -

Brain-derived neurotrophic factor - Wikipedia, the free encyclopedia
Although the vast majority of neurons in the mammalian brain are formed prenatally, parts of the adult brain retain the ability to grow new neurons ...

40 - A rummy derived italian card game ' Scala 40 ' - free on the App Store on iTunes
Get 40 - A rummy derived italian card game ' Scala 40 ' - free on the App Store. See screenshots and ratings, and read customer reviews.

Jeff Seeney orders Moreton Bay Regional Council to remove references to climate change-derived sea level ...
Queensland's Deputy Premier forces all references to climate change-derived sea level rises be removed from a council's development plan.

CSIS may use intelligence derived from torture, Toews says
Public Safety Minister Vic Toews has reversed Canadian policy, quietly directing Canada's spy agency to use information that may have been extracted ...

Alfa Romeo wants to build a Ferrari-derived V6 engine
Alfa Romeo is working on two new engines – a "high output" turbo-four and a "Ferrari-derived" V6

【cell】美国大学科研小组成功制作人类克隆ES细胞- Human Embryonic Stem Cells Derived by Somatic Cell N - 医药生命科学动态跟踪 -丁香园论坛
Reprogramming somatic cells into pluripotent embryonic stem cells (ESCs) by somatic cell nuclear transfer (SCNT) has been envisioned as an approach ...

The Lone Star Le Mans part two: Road-derived racers
Elle Cayabyab Gitlin The GTLM field takes the green flag for the TUSC race. 12 more images in gallery Last month, we were at the Circuit of ...

Official: Peugeot reveals Le Mans-derived 208 Hybrid FE prototype
Filed under: Concept Cars , Frankfurt Motor Show , Hybrid , Europe , Hatchback , Peugeot You can't leave a team of racing engineers sitting ...

Honda N600-derived retro city car revealed?
... on our shores, however. With its diminutive size and output, odds are this one will stay reserved for the Japanese market. Honda N600-derived ...

Ted Cruz's office says "in the mid-1990s, the Harvard Law School faculty included numerous self-described ...
That's in response to a New Yorker article quoting something Cruz said in a speech 3 years ago. (What Cruz said back then, at an Americans for ...

Resources last updated: 1/19/2016 6:54:54 PM