469,954 Members | 1,722 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,954 developers. It's quick & easy.

@ OutputCache in usercontrol problem

Hi to All,

I am using <% @ OutputCache Duration="60"
VaryByParam="none" %> in my
usercontrol say "myControl.ascx". This user control has a
property say
"title".

Now am Dynamically Loading this control in "myPage.aspx"
like this
Control ctl = LoadControl("myControl.ascx").
and then performing casting operation in order to set the
property value
((myControl)ctl).title = "Welcome to my Site"

But when i run the page it gives me following error
System.InvalidCastException. Specified cast is not valid.

And the beauty of this problem is that when i remove the
line <% @
OutputCache Duration="60" VaryByParam="none" %> The page
successfully
executes.
Please suggest.

Thanx in advance
Marshal


Nov 17 '05 #1
3 2153
make sure that the header information for your control
file contains a class name
eg <%Control ClassName="myControl"%>

for further info on loading controls dynamically:

http://msdn.microsoft.com/library/default.asp?
url=/library/en-
us/cpguide/html/cpconinstantiatingusercontrolsprogrammatica
lly.asp

also note: if the user control supports caching, the
object returned from this method is not actually a
UserControl, but a PartialCachingControl.
-----Original Message-----
Hi to All,

I am using <% @ OutputCache Duration="60"
VaryByParam="none" %> in my
usercontrol say "myControl.ascx". This user control has a
property say
"title".

Now am Dynamically Loading this control in "myPage.aspx"
like this
Control ctl = LoadControl("myControl.ascx").
and then performing casting operation in order to set the
property value
((myControl)ctl).title = "Welcome to my Site"

But when i run the page it gives me following error
System.InvalidCastException. Specified cast is not valid.

And the beauty of this problem is that when i remove the
line <% @
OutputCache Duration="60" VaryByParam="none" %> The page
successfully
executes.
Please suggest.

Thanx in advance
Marshal


.

Nov 17 '05 #2

Hi rory,

i have checked the className its correct
As u r telling me that return type is
PartialCachingControl not usercontrol so now how do i
access the property of the control.
i guess am doing wrong casting..

Marshall

-----Original Message-----
make sure that the header information for your control
file contains a class name
eg <%Control ClassName="myControl"%>

for further info on loading controls dynamically:
http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/cpguide/html/cpconinstantiatingusercontrolsprogrammatic ally.asp

also note: if the user control supports caching, the
object returned from this method is not actually a
UserControl, but a PartialCachingControl.
-----Original Message-----
Hi to All,

I am using <% @ OutputCache Duration="60"
VaryByParam="none" %> in my
usercontrol say "myControl.ascx". This user control has aproperty say
"title".

Now am Dynamically Loading this control in "myPage.aspx"
like this
Control ctl = LoadControl("myControl.ascx").
and then performing casting operation in order to set theproperty value
((myControl)ctl).title = "Welcome to my Site"

But when i run the page it gives me following error
System.InvalidCastException. Specified cast is not valid.

And the beauty of this problem is that when i remove the
line <% @
OutputCache Duration="60" VaryByParam="none" %> The page
successfully
executes.
Please suggest.

Thanx in advance
Marshal


.

.

Nov 17 '05 #3

Hi rory,

i have checked the className its correct
As u r telling me that return type is
PartialCachingControl not usercontrol so now how do i
access the property of the control.
i guess am doing wrong casting..

Marshall

-----Original Message-----
make sure that the header information for your control
file contains a class name
eg <%Control ClassName="myControl"%>

for further info on loading controls dynamically:
http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/cpguide/html/cpconinstantiatingusercontrolsprogrammatic ally.asp

also note: if the user control supports caching, the
object returned from this method is not actually a
UserControl, but a PartialCachingControl.
-----Original Message-----
Hi to All,

I am using <% @ OutputCache Duration="60"
VaryByParam="none" %> in my
usercontrol say "myControl.ascx". This user control has aproperty say
"title".

Now am Dynamically Loading this control in "myPage.aspx"
like this
Control ctl = LoadControl("myControl.ascx").
and then performing casting operation in order to set theproperty value
((myControl)ctl).title = "Welcome to my Site"

But when i run the page it gives me following error
System.InvalidCastException. Specified cast is not valid.

And the beauty of this problem is that when i remove the
line <% @
OutputCache Duration="60" VaryByParam="none" %> The page
successfully
executes.
Please suggest.

Thanx in advance
Marshal


.

.

Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by eriera1 | last post: by
1 post views Thread by Johan Nedin | last post: by
5 posts views Thread by Arpan | last post: by
2 posts views Thread by Nalaka | last post: by
3 posts views Thread by =?Utf-8?B?TWlndWVsIElzaWRvcm8=?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.