Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. usercontrol caching

usercontrol caching

Scheduled Pinned Locked Moved ASP.NET
helpdesigndockerquestion
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    marky777
    wrote on last edited by
    #1

    Hi. I need to cache a usercontrol on a page. I have tried: <%@ OutputCache Duration = "100" VaryByParam="none" %> in the design of the UC. And it gives the OBJECT NOT SET TO AN INSTANCE... error on the container page when i try to reference the UC. I have also tried: Response.Cache.SetExpires(DateTime.Now.AddSeconds(100)); Response.Cache.SetCacheability(HttpCacheability.Public); in the page load of the usercontrol. In the container page code i try: if (UCarticles1.CachePolicy.SupportsCaching) { UCarticles1.CachePolicy.Duration = new TimeSpan(0,0,20); } But I get the value of false from the if statement. Can someone help me please? What am I doing wrong? Thanks for your help.:-O

    C N 2 Replies Last reply
    0
    • M marky777

      Hi. I need to cache a usercontrol on a page. I have tried: <%@ OutputCache Duration = "100" VaryByParam="none" %> in the design of the UC. And it gives the OBJECT NOT SET TO AN INSTANCE... error on the container page when i try to reference the UC. I have also tried: Response.Cache.SetExpires(DateTime.Now.AddSeconds(100)); Response.Cache.SetCacheability(HttpCacheability.Public); in the page load of the usercontrol. In the container page code i try: if (UCarticles1.CachePolicy.SupportsCaching) { UCarticles1.CachePolicy.Duration = new TimeSpan(0,0,20); } But I get the value of false from the if statement. Can someone help me please? What am I doing wrong? Thanks for your help.:-O

      C Offline
      C Offline
      Chetan Ranpariya
      wrote on last edited by
      #2

      Hi, Caching in UserControls is called Fragment Caching. When u use Fragment Caching you can not perform any operation with the instance of that usercontrol in the container page's codebehind. and if u try to do so u will get NullReferenceException. I hope this will help you.

      Thanks and Regards, Chetan Ranpariya

      M 1 Reply Last reply
      0
      • C Chetan Ranpariya

        Hi, Caching in UserControls is called Fragment Caching. When u use Fragment Caching you can not perform any operation with the instance of that usercontrol in the container page's codebehind. and if u try to do so u will get NullReferenceException. I hope this will help you.

        Thanks and Regards, Chetan Ranpariya

        M Offline
        M Offline
        marky777
        wrote on last edited by
        #3

        Thanks for that. Can you give some sort of example? Thanks

        C 1 Reply Last reply
        0
        • M marky777

          Thanks for that. Can you give some sort of example? Thanks

          C Offline
          C Offline
          Chetan Ranpariya
          wrote on last edited by
          #4

          Hi, Your usercontrol itself is an example. You just remove caching feature from your user control and then try to run you application. I m sure u wont get exception at that time.

          Thanks and Regards, Chetan Ranpariya

          M 1 Reply Last reply
          0
          • C Chetan Ranpariya

            Hi, Your usercontrol itself is an example. You just remove caching feature from your user control and then try to run you application. I m sure u wont get exception at that time.

            Thanks and Regards, Chetan Ranpariya

            M Offline
            M Offline
            marky777
            wrote on last edited by
            #5

            I NEED caching to run my app., hence I cannot remove the caching feature. I want the contents of the UC to be cached for 2 minutes and then afterwards, get the updated contents and display on container page and then cached again... Thanks

            C 1 Reply Last reply
            0
            • M marky777

              I NEED caching to run my app., hence I cannot remove the caching feature. I want the contents of the UC to be cached for 2 minutes and then afterwards, get the updated contents and display on container page and then cached again... Thanks

              C Offline
              C Offline
              Chetan Ranpariya
              wrote on last edited by
              #6

              Hi, If its neccessary to user Caching in ur usercontrol then you should choose some other approach to implement the functionality that u want to implement by using reference of UC in the page codebehind.

              Thanks and Regards, Chetan Ranpariya

              M 1 Reply Last reply
              0
              • C Chetan Ranpariya

                Hi, If its neccessary to user Caching in ur usercontrol then you should choose some other approach to implement the functionality that u want to implement by using reference of UC in the page codebehind.

                Thanks and Regards, Chetan Ranpariya

                M Offline
                M Offline
                marky777
                wrote on last edited by
                #7

                Thanks. I'll see what I can come up with.

                1 Reply Last reply
                0
                • M marky777

                  Hi. I need to cache a usercontrol on a page. I have tried: <%@ OutputCache Duration = "100" VaryByParam="none" %> in the design of the UC. And it gives the OBJECT NOT SET TO AN INSTANCE... error on the container page when i try to reference the UC. I have also tried: Response.Cache.SetExpires(DateTime.Now.AddSeconds(100)); Response.Cache.SetCacheability(HttpCacheability.Public); in the page load of the usercontrol. In the container page code i try: if (UCarticles1.CachePolicy.SupportsCaching) { UCarticles1.CachePolicy.Duration = new TimeSpan(0,0,20); } But I get the value of false from the if statement. Can someone help me please? What am I doing wrong? Thanks for your help.:-O

                  N Offline
                  N Offline
                  Nouman Bhatti
                  wrote on last edited by
                  #8

                  Add the following element to the OutputCache directive for your usercontrol VaryByControl= name of the property by which u want to cache your control

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups