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

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
 
M

Matt Berther

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).
 
D

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).

Argh. Duh! Missed the obvious.

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

-Darrel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top