logo       

inheriting from a custom User Control: msg#00095

windows.devel.dotnet.web

Subject: inheriting from a custom User Control

I use code behind on most of the stuff I do. I am currently rewriting an
asp.net web application so that It can be more customizable. I have a few
(6) user controls (in .ascx/ascx.cs files). Instead of having them derive
from System.Web.UI.UserControl, I want to create a base class that derives
from UserControl and then have them derive from my class (MyControl). Is
there any good documentation on this with source code examples. What I want
to actually accomplish is being able to dynamically load them using data in a
SQL database.. example:

MyControl contains a property m_strOptions which all other derived controls
have to implement.

yahoofriendslist (in yahoo.ascx/yahoo.ascx.cs) derives from MyControl.
stockprofile (in stocks.ascs/stocks.ascx.cs) derives from MyControl.

I get 2 values from a database at this point with (as an example) I'm not
showing the database calls, but the end results of the values in the
following strings:

String strControl = "yahoo";
String strOptions = "bayercs2k::princess_nessa24::someone_else";

*** OR ***

String strControl = "stocks";
String strOptions = "AXL::WAL::GM::IBM";

Or other similar information.. I only gave 2 examples of my User Controls to
attempt to illustrate what I'm trying to accomplish.

and then run the following:

MyControl DynamicControl = LoadControl( strControl + ".ascx" );
DynamicControl.m_strOptions = strOptions;
PlaceHolder01.Controls.Add(DynamicControl);

and I have a <asp:placeholder ID=PlaceHolder01 runat=server /> in part of my
HTML.

I'm modifying the code that used to be working without the base class
MyControl, but in the old code I have to deal with an ever growing switch
statement everytime I add a new UserControl. This method will get rather
cumbersome quickly. and now that I've added the MyControl I get an error
message like the following:

Compiler Error Message: CS0234: The type or namespace name 'MyControl' does
not exist in the class or namespace 'mydundee' (are you missing an assembly
reference?)

I don't know if I'm clearly stating what I want to do, or if it is possible.
But if anyone can understand my ramblings and can point me to some good
documentation, it would be greatly appreciated.

Stephen Bayer
stephen@xxxxxxxxxxxxxxx

===================================
This list is hosted by DevelopMentor® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise