Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > @ OutputCache in usercontrol problem

Reply
Thread Tools

@ OutputCache in usercontrol problem

 
 
marshal
Guest
Posts: n/a
 
      08-07-2003
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






 
Reply With Quote
 
 
 
 
Rory
Guest
Posts: n/a
 
      08-07-2003
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
>
>
>
>
>
>
>.
>

 
Reply With Quote
 
 
 
 
Marshal
Guest
Posts: n/a
 
      08-07-2003

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

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

>.
>

 
Reply With Quote
 
Marshal
Guest
Posts: n/a
 
      08-07-2003

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

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

>.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Interesting OutputCache expiration problem yashgt@gmail.com ASP .Net 0 10-06-2007 04:58 PM
How to remove cached userCOntrol for OutputCache ABCL ASP .Net 1 03-22-2007 08:19 AM
Postback problem with usercontrol in usercontrol Mark van Bree ASP .Net Web Controls 1 05-30-2006 08:27 PM
Can we use a usercontrol inside a usercontrol Rajesh Tiwari ASP .Net 0 08-12-2003 03:56 PM
Use LoadControl to load a usercontrol but the webcontrol in the usercontrol can not AutoPostBack huobazi ASP .Net 1 07-03-2003 03:14 AM



Advertisments