Using a base class for a loaded UC (Part III)

  • Thread starter Thread starter darrel
  • Start date Start date
D

darrel

Continuing my ongoing journey through base classes...

Thanks to help from some folks, I think I've gotten my syntax close (but not
quite) where it needs to be.

What I am doing: trying to load a variety of usercontrols programtically and
then assigning property values to them.

What I have:

I created a baseclass for these controls that will be loaded:

-------------------------
Public Class BaseLoadedControl
Inherits System.Web.UI.UserControl

public siteID as String

End Class
-------------------------


Then, in my usercontrol that I am using to then load one of these controls,
I have this:

-------------------------
dim customContentControl as BaseLoadedControl
customContentControl = CType(Page.LoadControl(thecontrol),
BaseLoadedControl)
'theControl = the string of the specific control I am loading...such as
sample.ascx
-------------------------

The problem is that gives me an 'invalid cast' error.

So, once again, I'm stuck. Anyone see where my logic and/or syntax may be
off?

-Darrel
 
Hello darrel,

In the codebehind for your ascx file, you'll have a line that says something
like (forgive my VB)

public class MyUserControl Inherits UserControl

The inherits needs to be modified to be BaseLoadedControl (or whatever you
named your base class).
 
Hello darrel,

In the codebehind for your ascx file, you'll have a line that says something
like (forgive my VB)

public class MyUserControl Inherits UserControl

The inherits needs to be modified to be BaseLoadedControl (or whatever you
named your base class).

Argh. Duh! Missed the obvious.

Thanks, Matt...I think everything is working. I really appreciate the help.

-Darrel
 
Back
Top