@ OutputCache in usercontrol problem

Discussion in 'ASP .Net' started by marshal, Aug 7, 2003.

  1. marshal

    marshal Guest

    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
     
    marshal, Aug 7, 2003
    #1
    1. Advertising

  2. marshal

    Rory Guest

    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
    >
    >
    >
    >
    >
    >
    >.
    >
     
    Rory, Aug 7, 2003
    #2
    1. Advertising

  3. marshal

    Marshal Guest

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

    >.
    >
     
    Marshal, Aug 7, 2003
    #3
  4. marshal

    Marshal Guest

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

    >.
    >
     
    Marshal, Aug 7, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. huobazi
    Replies:
    1
    Views:
    742
    David Waz...
    Jul 3, 2003
  2. Rajesh Tiwari

    Can we use a usercontrol inside a usercontrol

    Rajesh Tiwari, Aug 12, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    444
    Rajesh Tiwari
    Aug 12, 2003
  3. ABCL
    Replies:
    1
    Views:
    540
    Masudur
    Mar 22, 2007
  4. Replies:
    0
    Views:
    403
  5. Mark van Bree

    Postback problem with usercontrol in usercontrol

    Mark van Bree, May 30, 2006, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    180
Loading...

Share This Page