class instance

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Göran Tänzer

    class instance

    Hi,

    i've written a class which does some calculations for my web application.
    These informatinos are different for each page request - the current user is
    not important.

    i have about 10 aspx pages and 20 ascx user controls. In most of these
    pages/user controls i need the informations of this class.

    First i created an instance of this class in every page/user control i
    needed the information with the result that a page with 10 usercontrols
    calculated the same information 11 times until the request is completed
    (=many redundant/identical calculations).

    So i created a static public instance of this class in the global.asax
    Application_Pre RequestHandlerE xecute event. The class is now created just
    once per page request and i can access it from the page and usercontrols like
    Global.MyClass. MyPoperties.

    But i'm not happy with this because i'm getting "accidental ly" errors like
    "Object has been disposed" when i access properties of this class. The errors
    occur on all thinkable usercontrols and pages. There is no special code
    fragment which raise the error.
    But this behavior occurs only if i the app has a very high load. (i
    simulated this on my dev box with the application test center).

    I searched for "global variables" to try another approach but i found
    nothing really usefull.

    Now i'm thinking of
    a) using a session instead of a static to hold the instance of this class or
    b) to create a instance of this class in the page_load/prerender event of a
    all my pages and make this instance accessable to the usercontrols with a
    property.

    or c) i'm completly wrong all the time and there's another/better way to
    access "global variables" accross a page and its usercontrols.

    Any suggestions?

    Thanks
  • Hans Kesting

    #2
    Re: class instance

    Göran Tänzer wrote:[color=blue]
    > Hi,
    >
    > i've written a class which does some calculations for my web
    > application. These informatinos are different for each page request -
    > the current user is not important.
    >
    > i have about 10 aspx pages and 20 ascx user controls. In most of these
    > pages/user controls i need the informations of this class.
    >
    > First i created an instance of this class in every page/user control i
    > needed the information with the result that a page with 10
    > usercontrols calculated the same information 11 times until the
    > request is completed (=many redundant/identical calculations).
    >
    > So i created a static public instance of this class in the global.asax
    > Application_Pre RequestHandlerE xecute event. The class is now created
    > just once per page request and i can access it from the page and
    > usercontrols like Global.MyClass. MyPoperties.
    >
    > But i'm not happy with this because i'm getting "accidental ly" errors
    > like "Object has been disposed" when i access properties of this
    > class. The errors occur on all thinkable usercontrols and pages.
    > There is no special code fragment which raise the error.
    > But this behavior occurs only if i the app has a very high load. (i
    > simulated this on my dev box with the application test center).
    >
    > I searched for "global variables" to try another approach but i found
    > nothing really usefull.
    >
    > Now i'm thinking of
    > a) using a session instead of a static to hold the instance of this
    > class or b) to create a instance of this class in the
    > page_load/prerender event of a all my pages and make this instance
    > accessable to the usercontrols with a property.
    >
    > or c) i'm completly wrong all the time and there's another/better way
    > to access "global variables" accross a page and its usercontrols.
    >
    > Any suggestions?
    >
    > Thanks[/color]

    One thing to remember when using static members, is that that same
    value is available for the entire (web-)application, that is: for all users
    that are requesting pages.

    You could use "Session" to store it:
    If I understand correctly, you can calculate the value in the page's
    Page_Init (or Page_Load) and store it in Session, the controls can
    then read it in the PreRender.

    Hans Kesting


    Comment

    • Kevin Spencer

      #3
      Re: class instance

      It's difficult to understand what your requirements for this class are, as
      you haven't been very specific about them ("does some calculations for my
      web application"). It SOUNDS like you may have a class which performs
      process only ("calculations" ). If that is the case, no instance of a class
      is necessary. Static methods (not static classes) do not require an instance
      of a class to execute. For example, the System.Math class has numerous
      methods for performing calcuations. Note that you never have to create an
      instance of this class to use its methods; they are static. So, what you
      should be doing, if I understand you correctly, is simply to create a public
      class with static members, and then simply use these static memebers without
      an instance of the class.

      --
      HTH,

      Kevin Spencer
      Microsoft MVP
      ..Net Developer
      The sun never sets on
      the Kingdom of Heaven

      "Göran Tänzer" <GranTnzer@disc ussions.microso ft.com> wrote in message
      news:96B2896B-7532-4CFC-8CDF-D4BC0C91BD0A@mi crosoft.com...[color=blue]
      > Hi,
      >
      > i've written a class which does some calculations for my web application.
      > These informatinos are different for each page request - the current user
      > is
      > not important.
      >
      > i have about 10 aspx pages and 20 ascx user controls. In most of these
      > pages/user controls i need the informations of this class.
      >
      > First i created an instance of this class in every page/user control i
      > needed the information with the result that a page with 10 usercontrols
      > calculated the same information 11 times until the request is completed
      > (=many redundant/identical calculations).
      >
      > So i created a static public instance of this class in the global.asax
      > Application_Pre RequestHandlerE xecute event. The class is now created just
      > once per page request and i can access it from the page and usercontrols
      > like
      > Global.MyClass. MyPoperties.
      >
      > But i'm not happy with this because i'm getting "accidental ly" errors like
      > "Object has been disposed" when i access properties of this class. The
      > errors
      > occur on all thinkable usercontrols and pages. There is no special code
      > fragment which raise the error.
      > But this behavior occurs only if i the app has a very high load. (i
      > simulated this on my dev box with the application test center).
      >
      > I searched for "global variables" to try another approach but i found
      > nothing really usefull.
      >
      > Now i'm thinking of
      > a) using a session instead of a static to hold the instance of this class
      > or
      > b) to create a instance of this class in the page_load/prerender event of
      > a
      > all my pages and make this instance accessable to the usercontrols with a
      > property.
      >
      > or c) i'm completly wrong all the time and there's another/better way to
      > access "global variables" accross a page and its usercontrols.
      >
      > Any suggestions?
      >
      > Thanks[/color]


      Comment

      • Göran Tänzer

        #4
        Re: class instance

        Hmm ok,

        this class is calculating some informations i need to work with my (M)CMS;
        lots of recursive stuff for navigation and multi language support, images and
        so on. If i access for example www.mysite.com/page.htm i need a lot of basic
        informations from my CMS in the aspx and ascx files to create this page.
        If i access the same public static method 5 times in my aspx page and 3
        times in 10 usercontrols within this aspx page i would calculate the same
        information 35 times.
        So i think its better to create one instance of this class which holds all
        the needed informations to create page.htm.


        "Kevin Spencer" wrote:
        [color=blue]
        > It's difficult to understand what your requirements for this class are, as
        > you haven't been very specific about them ("does some calculations for my
        > web application"). It SOUNDS like you may have a class which performs
        > process only ("calculations" ). If that is the case, no instance of a class
        > is necessary. Static methods (not static classes) do not require an instance
        > of a class to execute. For example, the System.Math class has numerous
        > methods for performing calcuations. Note that you never have to create an
        > instance of this class to use its methods; they are static. So, what you
        > should be doing, if I understand you correctly, is simply to create a public
        > class with static members, and then simply use these static memebers without
        > an instance of the class.
        >
        > --
        > HTH,
        >
        > Kevin Spencer
        > Microsoft MVP
        > ..Net Developer
        > The sun never sets on
        > the Kingdom of Heaven
        >
        > "Göran Tänzer" <GranTnzer@disc ussions.microso ft.com> wrote in message
        > news:96B2896B-7532-4CFC-8CDF-D4BC0C91BD0A@mi crosoft.com...[color=green]
        > > Hi,
        > >
        > > i've written a class which does some calculations for my web application.
        > > These informatinos are different for each page request - the current user
        > > is
        > > not important.
        > >
        > > i have about 10 aspx pages and 20 ascx user controls. In most of these
        > > pages/user controls i need the informations of this class.
        > >
        > > First i created an instance of this class in every page/user control i
        > > needed the information with the result that a page with 10 usercontrols
        > > calculated the same information 11 times until the request is completed
        > > (=many redundant/identical calculations).
        > >
        > > So i created a static public instance of this class in the global.asax
        > > Application_Pre RequestHandlerE xecute event. The class is now created just
        > > once per page request and i can access it from the page and usercontrols
        > > like
        > > Global.MyClass. MyPoperties.
        > >
        > > But i'm not happy with this because i'm getting "accidental ly" errors like
        > > "Object has been disposed" when i access properties of this class. The
        > > errors
        > > occur on all thinkable usercontrols and pages. There is no special code
        > > fragment which raise the error.
        > > But this behavior occurs only if i the app has a very high load. (i
        > > simulated this on my dev box with the application test center).
        > >
        > > I searched for "global variables" to try another approach but i found
        > > nothing really usefull.
        > >
        > > Now i'm thinking of
        > > a) using a session instead of a static to hold the instance of this class
        > > or
        > > b) to create a instance of this class in the page_load/prerender event of
        > > a
        > > all my pages and make this instance accessable to the usercontrols with a
        > > property.
        > >
        > > or c) i'm completly wrong all the time and there's another/better way to
        > > access "global variables" accross a page and its usercontrols.
        > >
        > > Any suggestions?
        > >
        > > Thanks[/color]
        >
        >
        >[/color]

        Comment

        • Kevin Spencer

          #5
          Re: class instance

          Well, again, I'm not sure what this "CMS" is, nor how it works. If you need
          an instance of a class on a per page basis, It would be best to use a
          (non-static) business class that you simply instantiate in the page. If you
          want to cache the business class, cache it in Session or Application.

          --
          HTH,

          Kevin Spencer
          Microsoft MVP
          ..Net Developer
          The sun never sets on
          the Kingdom of Heaven

          "Göran Tänzer" <GranTnzer@disc ussions.microso ft.com> wrote in message
          news:E580484A-C889-48BF-A86C-E79200180B90@mi crosoft.com...[color=blue]
          > Hmm ok,
          >
          > this class is calculating some informations i need to work with my (M)CMS;
          > lots of recursive stuff for navigation and multi language support, images
          > and
          > so on. If i access for example www.mysite.com/page.htm i need a lot of
          > basic
          > informations from my CMS in the aspx and ascx files to create this page.
          > If i access the same public static method 5 times in my aspx page and 3
          > times in 10 usercontrols within this aspx page i would calculate the same
          > information 35 times.
          > So i think its better to create one instance of this class which holds all
          > the needed informations to create page.htm.
          >
          >
          > "Kevin Spencer" wrote:
          >[color=green]
          >> It's difficult to understand what your requirements for this class are,
          >> as
          >> you haven't been very specific about them ("does some calculations for my
          >> web application"). It SOUNDS like you may have a class which performs
          >> process only ("calculations" ). If that is the case, no instance of a
          >> class
          >> is necessary. Static methods (not static classes) do not require an
          >> instance
          >> of a class to execute. For example, the System.Math class has numerous
          >> methods for performing calcuations. Note that you never have to create an
          >> instance of this class to use its methods; they are static. So, what you
          >> should be doing, if I understand you correctly, is simply to create a
          >> public
          >> class with static members, and then simply use these static memebers
          >> without
          >> an instance of the class.
          >>
          >> --
          >> HTH,
          >>
          >> Kevin Spencer
          >> Microsoft MVP
          >> ..Net Developer
          >> The sun never sets on
          >> the Kingdom of Heaven
          >>
          >> "Göran Tänzer" <GranTnzer@disc ussions.microso ft.com> wrote in message
          >> news:96B2896B-7532-4CFC-8CDF-D4BC0C91BD0A@mi crosoft.com...[color=darkred]
          >> > Hi,
          >> >
          >> > i've written a class which does some calculations for my web
          >> > application.
          >> > These informatinos are different for each page request - the current
          >> > user
          >> > is
          >> > not important.
          >> >
          >> > i have about 10 aspx pages and 20 ascx user controls. In most of these
          >> > pages/user controls i need the informations of this class.
          >> >
          >> > First i created an instance of this class in every page/user control i
          >> > needed the information with the result that a page with 10 usercontrols
          >> > calculated the same information 11 times until the request is completed
          >> > (=many redundant/identical calculations).
          >> >
          >> > So i created a static public instance of this class in the global.asax
          >> > Application_Pre RequestHandlerE xecute event. The class is now created
          >> > just
          >> > once per page request and i can access it from the page and
          >> > usercontrols
          >> > like
          >> > Global.MyClass. MyPoperties.
          >> >
          >> > But i'm not happy with this because i'm getting "accidental ly" errors
          >> > like
          >> > "Object has been disposed" when i access properties of this class. The
          >> > errors
          >> > occur on all thinkable usercontrols and pages. There is no special code
          >> > fragment which raise the error.
          >> > But this behavior occurs only if i the app has a very high load. (i
          >> > simulated this on my dev box with the application test center).
          >> >
          >> > I searched for "global variables" to try another approach but i found
          >> > nothing really usefull.
          >> >
          >> > Now i'm thinking of
          >> > a) using a session instead of a static to hold the instance of this
          >> > class
          >> > or
          >> > b) to create a instance of this class in the page_load/prerender event
          >> > of
          >> > a
          >> > all my pages and make this instance accessable to the usercontrols with
          >> > a
          >> > property.
          >> >
          >> > or c) i'm completly wrong all the time and there's another/better way
          >> > to
          >> > access "global variables" accross a page and its usercontrols.
          >> >
          >> > Any suggestions?
          >> >
          >> > Thanks[/color]
          >>
          >>
          >>[/color][/color]


          Comment

          • Juan T. Llibre

            #6
            Re: class instance

            CMS = Content Management System



            Juan T. Llibre
            ASP.NET MVP

            Foros de ASP.NET en Español
            Ven, y hablemos de ASP.NET...
            =============== =======

            "Kevin Spencer" <kevin@DIESPAMM ERSDIEtakempis. com> wrote in message
            news:%23DEOaw6i FHA.812@TK2MSFT NGP10.phx.gbl.. .[color=blue]
            > Well, again, I'm not sure what this "CMS" is, nor how it works. If you need an instance
            > of a class on a per page basis, It would be best to use a (non-static) business class
            > that you simply instantiate in the page. If you want to cache the business class, cache
            > it in Session or Application.
            >
            > --
            > HTH,
            >
            > Kevin Spencer
            > Microsoft MVP
            > .Net Developer
            > The sun never sets on
            > the Kingdom of Heaven
            >
            > "Göran Tänzer" <GranTnzer@disc ussions.microso ft.com> wrote in message
            > news:E580484A-C889-48BF-A86C-E79200180B90@mi crosoft.com...[color=green]
            >> Hmm ok,
            >>
            >> this class is calculating some informations i need to work with my (M)CMS;
            >> lots of recursive stuff for navigation and multi language support, images and
            >> so on. If i access for example www.mysite.com/page.htm i need a lot of basic
            >> informations from my CMS in the aspx and ascx files to create this page.
            >> If i access the same public static method 5 times in my aspx page and 3
            >> times in 10 usercontrols within this aspx page i would calculate the same
            >> information 35 times.
            >> So i think its better to create one instance of this class which holds all
            >> the needed informations to create page.htm.
            >>
            >>
            >> "Kevin Spencer" wrote:
            >>[color=darkred]
            >>> It's difficult to understand what your requirements for this class are, as
            >>> you haven't been very specific about them ("does some calculations for my
            >>> web application"). It SOUNDS like you may have a class which performs
            >>> process only ("calculations" ). If that is the case, no instance of a class
            >>> is necessary. Static methods (not static classes) do not require an instance
            >>> of a class to execute. For example, the System.Math class has numerous
            >>> methods for performing calcuations. Note that you never have to create an
            >>> instance of this class to use its methods; they are static. So, what you
            >>> should be doing, if I understand you correctly, is simply to create a public
            >>> class with static members, and then simply use these static memebers without
            >>> an instance of the class.
            >>>
            >>> --
            >>> HTH,
            >>>
            >>> Kevin Spencer
            >>> Microsoft MVP
            >>> ..Net Developer
            >>> The sun never sets on
            >>> the Kingdom of Heaven
            >>>
            >>> "Göran Tänzer" <GranTnzer@disc ussions.microso ft.com> wrote in message
            >>> news:96B2896B-7532-4CFC-8CDF-D4BC0C91BD0A@mi crosoft.com...
            >>> > Hi,
            >>> >
            >>> > i've written a class which does some calculations for my web application.
            >>> > These informatinos are different for each page request - the current user
            >>> > is
            >>> > not important.
            >>> >
            >>> > i have about 10 aspx pages and 20 ascx user controls. In most of these
            >>> > pages/user controls i need the informations of this class.
            >>> >
            >>> > First i created an instance of this class in every page/user control i
            >>> > needed the information with the result that a page with 10 usercontrols
            >>> > calculated the same information 11 times until the request is completed
            >>> > (=many redundant/identical calculations).
            >>> >
            >>> > So i created a static public instance of this class in the global.asax
            >>> > Application_Pre RequestHandlerE xecute event. The class is now created just
            >>> > once per page request and i can access it from the page and usercontrols
            >>> > like
            >>> > Global.MyClass. MyPoperties.
            >>> >
            >>> > But i'm not happy with this because i'm getting "accidental ly" errors like
            >>> > "Object has been disposed" when i access properties of this class. The
            >>> > errors
            >>> > occur on all thinkable usercontrols and pages. There is no special code
            >>> > fragment which raise the error.
            >>> > But this behavior occurs only if i the app has a very high load. (i
            >>> > simulated this on my dev box with the application test center).
            >>> >
            >>> > I searched for "global variables" to try another approach but i found
            >>> > nothing really usefull.
            >>> >
            >>> > Now i'm thinking of
            >>> > a) using a session instead of a static to hold the instance of this class
            >>> > or
            >>> > b) to create a instance of this class in the page_load/prerender event of
            >>> > a
            >>> > all my pages and make this instance accessable to the usercontrols with a
            >>> > property.
            >>> >
            >>> > or c) i'm completly wrong all the time and there's another/better way to
            >>> > access "global variables" accross a page and its usercontrols.
            >>> >
            >>> > Any suggestions?
            >>> >
            >>> > Thanks
            >>>
            >>>
            >>>[/color][/color]
            >
            >[/color]


            Comment

            • Kevin Spencer

              #7
              Re: class instance

              Hi Juan,
              [color=blue]
              > CMS = Content Management System[/color]

              I know that much! However, the term is generic, and does not imply any real
              information about how the particular CMS works. It only implies that some
              application manages some content. And there are plenty of them around. They
              come in all shapes and sizes.

              --

              Kevin Spencer
              Microsoft MVP
              ..Net Developer
              The sun never sets on
              the Kingdom of Heaven

              "Juan T. Llibre" <nomailreplies@ nowhere.com> wrote in message
              news:OQVXrr7iFH A.3568@tk2msftn gp13.phx.gbl...[color=blue]
              > CMS = Content Management System
              >
              >
              >
              > Juan T. Llibre
              > ASP.NET MVP
              > http://asp.net.do/foros/
              > Foros de ASP.NET en Español
              > Ven, y hablemos de ASP.NET...
              > =============== =======
              >
              > "Kevin Spencer" <kevin@DIESPAMM ERSDIEtakempis. com> wrote in message
              > news:%23DEOaw6i FHA.812@TK2MSFT NGP10.phx.gbl.. .[color=green]
              >> Well, again, I'm not sure what this "CMS" is, nor how it works. If you
              >> need an instance of a class on a per page basis, It would be best to use
              >> a (non-static) business class that you simply instantiate in the page. If
              >> you want to cache the business class, cache it in Session or Application.
              >>
              >> --
              >> HTH,
              >>
              >> Kevin Spencer
              >> Microsoft MVP
              >> .Net Developer
              >> The sun never sets on
              >> the Kingdom of Heaven
              >>
              >> "Göran Tänzer" <GranTnzer@disc ussions.microso ft.com> wrote in message
              >> news:E580484A-C889-48BF-A86C-E79200180B90@mi crosoft.com...[color=darkred]
              >>> Hmm ok,
              >>>
              >>> this class is calculating some informations i need to work with my
              >>> (M)CMS;
              >>> lots of recursive stuff for navigation and multi language support,
              >>> images and
              >>> so on. If i access for example www.mysite.com/page.htm i need a lot of
              >>> basic
              >>> informations from my CMS in the aspx and ascx files to create this page.
              >>> If i access the same public static method 5 times in my aspx page and 3
              >>> times in 10 usercontrols within this aspx page i would calculate the
              >>> same
              >>> information 35 times.
              >>> So i think its better to create one instance of this class which holds
              >>> all
              >>> the needed informations to create page.htm.
              >>>
              >>>
              >>> "Kevin Spencer" wrote:
              >>>
              >>>> It's difficult to understand what your requirements for this class are,
              >>>> as
              >>>> you haven't been very specific about them ("does some calculations for
              >>>> my
              >>>> web application"). It SOUNDS like you may have a class which performs
              >>>> process only ("calculations" ). If that is the case, no instance of a
              >>>> class
              >>>> is necessary. Static methods (not static classes) do not require an
              >>>> instance
              >>>> of a class to execute. For example, the System.Math class has numerous
              >>>> methods for performing calcuations. Note that you never have to create
              >>>> an
              >>>> instance of this class to use its methods; they are static. So, what
              >>>> you
              >>>> should be doing, if I understand you correctly, is simply to create a
              >>>> public
              >>>> class with static members, and then simply use these static memebers
              >>>> without
              >>>> an instance of the class.
              >>>>
              >>>> --
              >>>> HTH,
              >>>>
              >>>> Kevin Spencer
              >>>> Microsoft MVP
              >>>> ..Net Developer
              >>>> The sun never sets on
              >>>> the Kingdom of Heaven
              >>>>
              >>>> "Göran Tänzer" <GranTnzer@disc ussions.microso ft.com> wrote in message
              >>>> news:96B2896B-7532-4CFC-8CDF-D4BC0C91BD0A@mi crosoft.com...
              >>>> > Hi,
              >>>> >
              >>>> > i've written a class which does some calculations for my web
              >>>> > application.
              >>>> > These informatinos are different for each page request - the current
              >>>> > user
              >>>> > is
              >>>> > not important.
              >>>> >
              >>>> > i have about 10 aspx pages and 20 ascx user controls. In most of
              >>>> > these
              >>>> > pages/user controls i need the informations of this class.
              >>>> >
              >>>> > First i created an instance of this class in every page/user control
              >>>> > i
              >>>> > needed the information with the result that a page with 10
              >>>> > usercontrols
              >>>> > calculated the same information 11 times until the request is
              >>>> > completed
              >>>> > (=many redundant/identical calculations).
              >>>> >
              >>>> > So i created a static public instance of this class in the
              >>>> > global.asax
              >>>> > Application_Pre RequestHandlerE xecute event. The class is now created
              >>>> > just
              >>>> > once per page request and i can access it from the page and
              >>>> > usercontrols
              >>>> > like
              >>>> > Global.MyClass. MyPoperties.
              >>>> >
              >>>> > But i'm not happy with this because i'm getting "accidental ly" errors
              >>>> > like
              >>>> > "Object has been disposed" when i access properties of this class.
              >>>> > The
              >>>> > errors
              >>>> > occur on all thinkable usercontrols and pages. There is no special
              >>>> > code
              >>>> > fragment which raise the error.
              >>>> > But this behavior occurs only if i the app has a very high load. (i
              >>>> > simulated this on my dev box with the application test center).
              >>>> >
              >>>> > I searched for "global variables" to try another approach but i found
              >>>> > nothing really usefull.
              >>>> >
              >>>> > Now i'm thinking of
              >>>> > a) using a session instead of a static to hold the instance of this
              >>>> > class
              >>>> > or
              >>>> > b) to create a instance of this class in the page_load/prerender
              >>>> > event of
              >>>> > a
              >>>> > all my pages and make this instance accessable to the usercontrols
              >>>> > with a
              >>>> > property.
              >>>> >
              >>>> > or c) i'm completly wrong all the time and there's another/better way
              >>>> > to
              >>>> > access "global variables" accross a page and its usercontrols.
              >>>> >
              >>>> > Any suggestions?
              >>>> >
              >>>> > Thanks
              >>>>
              >>>>
              >>>>[/color]
              >>
              >>[/color]
              >
              >[/color]


              Comment

              • Juan T. Llibre

                #8
                Re: class instance

                re:[color=blue]
                >there are plenty of them around[/color]

                Most are overpriced, too... ;-)



                Juan T. Llibre
                ASP.NET MVP

                Foros de ASP.NET en Español
                Ven, y hablemos de ASP.NET...
                =============== =======

                "Kevin Spencer" <kevin@DIESPAMM ERSDIEtakempis. com> wrote in message
                news:eebi7u7iFH A.1232@TK2MSFTN GP15.phx.gbl...[color=blue]
                > Hi Juan,
                >[color=green]
                >> CMS = Content Management System[/color]
                >
                > I know that much! However, the term is generic, and does not imply any real information
                > about how the particular CMS works. It only implies that some application manages some
                > content. And there are plenty of them around. They come in all shapes and sizes.
                >
                > --
                >
                > Kevin Spencer
                > Microsoft MVP
                > .Net Developer
                > The sun never sets on
                > the Kingdom of Heaven
                >
                > "Juan T. Llibre" <nomailreplies@ nowhere.com> wrote in message
                > news:OQVXrr7iFH A.3568@tk2msftn gp13.phx.gbl...[color=green]
                >> CMS = Content Management System
                >>
                >>
                >>
                >> Juan T. Llibre
                >> ASP.NET MVP
                >> http://asp.net.do/foros/
                >> Foros de ASP.NET en Español
                >> Ven, y hablemos de ASP.NET...
                >> =============== =======
                >>
                >> "Kevin Spencer" <kevin@DIESPAMM ERSDIEtakempis. com> wrote in message
                >> news:%23DEOaw6i FHA.812@TK2MSFT NGP10.phx.gbl.. .[color=darkred]
                >>> Well, again, I'm not sure what this "CMS" is, nor how it works. If you need an
                >>> instance of a class on a per page basis, It would be best to use a (non-static)
                >>> business class that you simply instantiate in the page. If you want to cache the
                >>> business class, cache it in Session or Application.
                >>>
                >>> --
                >>> HTH,
                >>>
                >>> Kevin Spencer
                >>> Microsoft MVP
                >>> .Net Developer
                >>> The sun never sets on
                >>> the Kingdom of Heaven
                >>>
                >>> "Göran Tänzer" <GranTnzer@disc ussions.microso ft.com> wrote in message
                >>> news:E580484A-C889-48BF-A86C-E79200180B90@mi crosoft.com...
                >>>> Hmm ok,
                >>>>
                >>>> this class is calculating some informations i need to work with my (M)CMS;
                >>>> lots of recursive stuff for navigation and multi language support, images and
                >>>> so on. If i access for example www.mysite.com/page.htm i need a lot of basic
                >>>> informations from my CMS in the aspx and ascx files to create this page.
                >>>> If i access the same public static method 5 times in my aspx page and 3
                >>>> times in 10 usercontrols within this aspx page i would calculate the same
                >>>> information 35 times.
                >>>> So i think its better to create one instance of this class which holds all
                >>>> the needed informations to create page.htm.
                >>>>
                >>>>
                >>>> "Kevin Spencer" wrote:
                >>>>
                >>>>> It's difficult to understand what your requirements for this class are, as
                >>>>> you haven't been very specific about them ("does some calculations for my
                >>>>> web application"). It SOUNDS like you may have a class which performs
                >>>>> process only ("calculations" ). If that is the case, no instance of a class
                >>>>> is necessary. Static methods (not static classes) do not require an instance
                >>>>> of a class to execute. For example, the System.Math class has numerous
                >>>>> methods for performing calcuations. Note that you never have to create an
                >>>>> instance of this class to use its methods; they are static. So, what you
                >>>>> should be doing, if I understand you correctly, is simply to create a public
                >>>>> class with static members, and then simply use these static memebers without
                >>>>> an instance of the class.
                >>>>>
                >>>>> --
                >>>>> HTH,
                >>>>>
                >>>>> Kevin Spencer
                >>>>> Microsoft MVP
                >>>>> ..Net Developer
                >>>>> The sun never sets on
                >>>>> the Kingdom of Heaven
                >>>>>
                >>>>> "Göran Tänzer" <GranTnzer@disc ussions.microso ft.com> wrote in message
                >>>>> news:96B2896B-7532-4CFC-8CDF-D4BC0C91BD0A@mi crosoft.com...
                >>>>> > Hi,
                >>>>> >
                >>>>> > i've written a class which does some calculations for my web application.
                >>>>> > These informatinos are different for each page request - the current user
                >>>>> > is
                >>>>> > not important.
                >>>>> >
                >>>>> > i have about 10 aspx pages and 20 ascx user controls. In most of these
                >>>>> > pages/user controls i need the informations of this class.
                >>>>> >
                >>>>> > First i created an instance of this class in every page/user control i
                >>>>> > needed the information with the result that a page with 10 usercontrols
                >>>>> > calculated the same information 11 times until the request is completed
                >>>>> > (=many redundant/identical calculations).
                >>>>> >
                >>>>> > So i created a static public instance of this class in the global.asax
                >>>>> > Application_Pre RequestHandlerE xecute event. The class is now created just
                >>>>> > once per page request and i can access it from the page and usercontrols
                >>>>> > like
                >>>>> > Global.MyClass. MyPoperties.
                >>>>> >
                >>>>> > But i'm not happy with this because i'm getting "accidental ly" errors like
                >>>>> > "Object has been disposed" when i access properties of this class. The
                >>>>> > errors
                >>>>> > occur on all thinkable usercontrols and pages. There is no special code
                >>>>> > fragment which raise the error.
                >>>>> > But this behavior occurs only if i the app has a very high load. (i
                >>>>> > simulated this on my dev box with the application test center).
                >>>>> >
                >>>>> > I searched for "global variables" to try another approach but i found
                >>>>> > nothing really usefull.
                >>>>> >
                >>>>> > Now i'm thinking of
                >>>>> > a) using a session instead of a static to hold the instance of this class
                >>>>> > or
                >>>>> > b) to create a instance of this class in the page_load/prerender event of
                >>>>> > a
                >>>>> > all my pages and make this instance accessable to the usercontrols with a
                >>>>> > property.
                >>>>> >
                >>>>> > or c) i'm completly wrong all the time and there's another/better way to
                >>>>> > access "global variables" accross a page and its usercontrols.
                >>>>> >
                >>>>> > Any suggestions?
                >>>>> >
                >>>>> > Thanks
                >>>>>
                >>>>>
                >>>>>
                >>>
                >>>[/color]
                >>
                >>[/color]
                >
                >[/color]


                Comment

                Working...