By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,132 Members | 1,417 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,132 IT Pros & Developers. It's quick & easy.

Base class casting exception

P: n/a
Hi all!

I created a new class, which has the UserControl as a base class.

Now I want to create an instance of my new class, by creating a new
usercontrol and casting it to my new class using the next line of code:

MyClass instance = (MyClass)((UserControl) Page.LoadControl("an_ascx.ascx"));

This is how I defined MyClass and its constructor:

public class MyClass : UserControl
{
public PortalGlobalModuleControl() : base()
{
this.RefreshPortalSettings();
} // Constructor
}
When I execute this line of code, I get an Invallid Cast exception. (Casting
from control to usercontrol is no problem).

What am I missing here? I thought this could not give any problems...

Thanks in advance,

Michel
Nov 16 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.