LoadControl and casting (???)

  • Thread starter Thierry Schembri
  • Start date
T

Thierry Schembri

Hello,

I'm facing to a strange problem (framework 2.0).

It's pretty simple : I load a custom web control called "Foo.ascx" (the
control class is "Foo").

Control c = LoadControl("/Foo.ascx");

Up there, it's ok and I can use c the way I want.

Then, I do :

Foo t = (Foo)c;

The following error occurs :

"Unable to cast object of type 'ASP.Foo_ascx' to type 'Foo'.

OK, I modify my line :

ASP.Foo_ascx t = (ASP.Foo_ascx)c;

And now, I get this exception (!!!) :

"Unable to cast object of type 'ASP.Foo_ascx' to type 'ASP.Foo_ascx'".

!!! I break the execution, rebuild the whole stuff and everything works
well now, no more error. But, as soon as I modify something without
rebuild, the exception occurs again (I have to rebuild) !!

Any idea ?

Thanks in advance.
 
T

Thierry Schembri

Hello Scott,

Thanks for the idea. I've added the @reference directive and it seems
it works. I will also have a look to the compilation batch directive (I
don't know it).
Thanks again.
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top