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. Persist a dataset across postbacks

Persist a dataset across postbacks

Scheduled Pinned Locked Moved ASP.NET
databasequestion
8 Posts 4 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.
  • T Offline
    T Offline
    tonymathewt
    wrote on last edited by
    #1

    What is the best approach to persist a dataset across postbacks so that users could manipulate the data in it and could be saved(to the database) at last.

    N L A 3 Replies Last reply
    0
    • T tonymathewt

      What is the best approach to persist a dataset across postbacks so that users could manipulate the data in it and could be saved(to the database) at last.

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      You can put it in ViewState.

      Best wishes, Navaneeth

      T 1 Reply Last reply
      0
      • T tonymathewt

        What is the best approach to persist a dataset across postbacks so that users could manipulate the data in it and could be saved(to the database) at last.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        You can use viewstate, but if the size of the dataset is very large, it will bloat the request and response size and can probably kill your app. Use a DataTable object and persist it in session. You can also try serializing the object to a database and save the key in viewstate. Each approach has its own advantages and disadvantages. You should try to find out what works best for you.

        T 1 Reply Last reply
        0
        • T tonymathewt

          What is the best approach to persist a dataset across postbacks so that users could manipulate the data in it and could be saved(to the database) at last.

          A Offline
          A Offline
          Abhishek Sur
          wrote on last edited by
          #4

          The best way is not to Persist the dataset ever. Just save the changes during postbacks and show the most recent data. Remember, the user might go next page on next date. Or might be there is a session timeout. If you store everything in context, that means errors might loose everything. ;)

          Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


          My Latest Articles-->** Microsoft Bing MAP using Javascript
          CLR objects in SQL Server 2005
          Uncommon C# Keywords
          /xml>

          T 1 Reply Last reply
          0
          • L Lost User

            You can use viewstate, but if the size of the dataset is very large, it will bloat the request and response size and can probably kill your app. Use a DataTable object and persist it in session. You can also try serializing the object to a database and save the key in viewstate. Each approach has its own advantages and disadvantages. You should try to find out what works best for you.

            T Offline
            T Offline
            tonymathewt
            wrote on last edited by
            #5

            Hello Shameel How about persisting the DataSet(as I have more than one DataTable) in a Session variable and clearing it(using Session.Remove()) while the user navigates away from the page?

            1 Reply Last reply
            0
            • N N a v a n e e t h

              You can put it in ViewState.

              Best wishes, Navaneeth

              T Offline
              T Offline
              tonymathewt
              wrote on last edited by
              #6

              I am using ViewState now but I notice the page is slower during reloads

              1 Reply Last reply
              0
              • A Abhishek Sur

                The best way is not to Persist the dataset ever. Just save the changes during postbacks and show the most recent data. Remember, the user might go next page on next date. Or might be there is a session timeout. If you store everything in context, that means errors might loose everything. ;)

                Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


                My Latest Articles-->** Microsoft Bing MAP using Javascript
                CLR objects in SQL Server 2005
                Uncommon C# Keywords
                /xml>

                T Offline
                T Offline
                tonymathewt
                wrote on last edited by
                #7

                Thank you Abhishek You re right. But here I am faced with a situation to reduce database hits rather than concurrency. I am having multiple tables so using DataSet. When I stored it in a ViewState variable I notice the page loading slower.

                A 1 Reply Last reply
                0
                • T tonymathewt

                  Thank you Abhishek You re right. But here I am faced with a situation to reduce database hits rather than concurrency. I am having multiple tables so using DataSet. When I stored it in a ViewState variable I notice the page loading slower.

                  A Offline
                  A Offline
                  Abhishek Sur
                  wrote on last edited by
                  #8

                  Dont load such a huge data in ViewState. When you request for something, you send viewstate with it(even if it is an AJAX request). After receiving the viewstate it decrypts it using Machine key. It then modifies the viewstate according to your serverside program and then finally encrypts it... converts the encrypted string to Base64 and written over Response stream. That means for every request this huge amount of task IIS has to perform. Hence slow output. We generally place EnableViewState = false for frequently visited pages to have better performance. So according to me writing a Dataset(which serializes it and write to page) is not good. On the other hand, Server memory is very low. If there are lots of connections, there might be a huge possibility to have Session OutofMemory. But if you dont have concurrent connections, you might use Session. But dont put the dataset, as there are a lots of properties which are not required. Rather make a list of DataRows and place them in session(Improves than writing DataSet). But still, I dont like this as well. If I was there, I will always compromise Database hits than Server memory. :thumbsup:

                  Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


                  My Latest Articles-->** Simplify Code Using NDepend
                  Basics of Bing Search API using .NET
                  Microsoft Bing MAP using Javascript

                  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