473,394 Members | 1,916 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

LoadControl and casting (???)

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.
Nov 19 '05 #1
2 1125
Hi Thierry:

Do you have an @ Reference directive in the aspx of the form using
LoadControl? If not, you'll come across these strange errors.

http://odetocode.com/Blogs/scott/arc...6/30/1889.aspx

I also suggest using <compilation batch="false"/> in web.config during
development. It will help to flush out these types of errors.

--
Scott
http://www.OdeToCode.com/blogs/scott/
On Sun, 09 Oct 2005 21:43:51 +0200, "Thierry Schembri"
<ts*******@hydromail.net> wrote:
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.


Nov 19 '05 #2
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.
Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: George Durzi | last post by:
I have a C# in my web application called BasePage. It inherits from System.Web.UI.Page. I'm using page inheritance in my web app so all my pages have an identical look and feel by inheriting from...
3
by: Robert Walter | last post by:
I want to user the Page method LoadControl inside the Global.asax.cs but when I instantiate a page and try it I get the following error... System.NullReferenceException: Object reference not set...
10
by: Umut Tezduyar | last post by:
It seems, it is caching it. The following code is an example for it. How can avoid from this. override void OnLoad (sender and eventargs) { Control control = this.LoadControl (path);...
8
by: Sam Kuehn | last post by:
How do I accomplish the fallowing (is it even possible). Say I write a UserControl "MyControl.ascx". Now I use LoadControl("MyControl.ascx"). But I really want MyControl to require parameters in...
2
by: Keith Patrick | last post by:
Maybe my expectations are just too low because I haven't read much documentation on this method, but basically, I am trying to load a user control dynamically without using a virtual path (I have...
1
by: Joe | last post by:
Hello All, I have a class that inherits from System.Web.UI.Page. In it I call the Page.LoadControl. I am having trouble with the virtual path that the LoadControl method accepts as its...
0
by: MattB | last post by:
I'm making a reusable class to load and populate user controls based on database values. I had the basic code working from codebehind, and now I'm moving it to a reusable class. Once in the...
1
by: Andreas | last post by:
Hallo zusammen, ich kämpfe seit Tagen mit folgendem Problem und habe bisher leider keine Lösung gefunden. Vielleicht kann mir jemand helfen: Ich möchte auf einer Seite (test.aspx) ein...
0
by: Carl Wright | last post by:
Hi I'm having this major issue loading a usercontrol at runtime using the overload on Loadcontrol(type,object). Here's the code in the aspx code-behind file Dim myControl As New Control Dim...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.