Pass huge Data from one page to another

Mohit Joshi 1 Reputation point

I am developing a Web Application and In that I want to pass huge Data from one page to another without using query string. I can't use query string because there are 8 to 10 values and some of the values are very big. Kindly provide me exact solution ASAP.

A set of technologies in the .NET Framework for building web applications and XML web services.
3,365 questions
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,489 questions
{count} votes

4 answers

Sort by: Most helpful
  1. AgaveJoe 26,676 Reputation points

    Store the "huge data" in a database. Then in the second page read the "huge data".

    0 comments No comments

  2. Rijwan Ansari 746 Reputation points MVP

    Hi @Mohit Joshi

    If there are 8-10 values, then you can use session, cookies or viewdata (MVC). If there are huge data then use database to store and retrieve those data temporary as suggested by AgaveJoe.

    0 comments No comments

  3. Albert Kallal 5,146 Reputation points

    As pointed out, often session() or even a database can be used.

    Now "big" is a relative term.

    For example, I find that to pass one or two values?

    I use session, but on target page - IsPostBack = False, I grab/get/move the values over to ViewState (if the values are required for code behind in that page to operate). Why transfer to ViewState?

    Well, remember, Session() is global to the one user. So, say I have a Gridview, and you select a row. I shove the PK database ID into session, and then say jump to the next page (probably to view details with that "one thing").

    So, say your shopping for a house, click on a row, and the jump to that view/buy/see one house page.

    But, now what happens if you open up a 2nd browser, or have two tabs open - and now click on another different house, and jump to the house view or buy page?

    Well, now you have two browsers open, but both have the same database row PK id in session. If you click on buy house, and your code behind uses that sesson(), then you can wind up buying the wrong house.

    So, then I follow this design pattern:

    session() - use it to pass values to the target/next landing page.
    On page load (IsPostBack = false), I transfer those values to Viewstate.

    That way, my applcation works fine if the user opens multiple browser pages open.

    but, keep in mind that Viewstate must be treated with care and love.

    Session() - server side based memory - global per one user - all code.

    ViewState() - browser based - and ONLY per one browser page.

    So, on each button click, each post-back, the ViewState travels up to the server, and then back down (it becomes part of the browser payload. As a result, if you stuff a lot of data or values into the ViewState, then you can hurt applcation performance - and even a simple button click on the web page that causes a post-back? ViewState() will also travel along for the ride.

    So, say I have to pass 8 values? Well, messing up and having 8 session() values, and then say 8 viewstate values is really messy as your applcation grows!

    So, I will say build a class to hold the values for a given page, or target page, say like this:

    Public Class CustomerValues
        Public InvoiceNumber As Integer
        Public CustomerID As Integer
        Public ProjectID As Integer
        Public COD As Boolean
    End Class

    So, now in code, I get great intel-sense, and I have a NICE grouping of values for the one page, (or to pass to the next page).

    So, now in code I can go like this:

    Dim Customer = New clsCustomer
    Customer.InvoiceID = 3434
    Customer.InvoiceNumber = 1343444
    Customer.ProjectID = 3443
    Customer.COD = false
    Session("CustInfo") = Customer
    so, that way, I can pass a "bunch" of values as one thing.
    On target page, I will then have this:
    If Not IsPostBack then
       Customer = session("CustInfo")
       ViewState("CustInfo") = Customer
    Customer = ViewState("custInfo")

    End if
    etc. etc.

    So, I suppose at this point in time, I should also empty out the session(), but the above gives the idea.

    but, the term "large amount of data" is perhaps an issue. How and why and where does this "large" amount of data come from? For example, if this is some customer data, or whatever? then in most cases just pass the database PK id, and on the target page, your code can then re-pull that data - and have use of the data when required.

    That "large" amount of data has to come from some place, and it is unlikely that large amount of data originated and came from the previous web page - so in most cases, you can just pass say some database PK ID, and the target page can then pull the data from the database. This way you don't over-load, or put too much into the session() memory.

    So, session() and especially ViewState have to be seen as bars of valuable gold - don't over use them, but use them to pass values, and the result is nice clean, and uncluttered URL's, and also in most cases a far more secure applcation (users can type in and change parameters used in urls's, but with session() and Viewstate(), they cannot.

    0 comments No comments

  4. Karen Payne MVP 35,286 Reputation points

    Unless what values are very big means in size but would recommend reading ASP.NET Core Performance Best Practices which has plenty of information to assist with this question.

    0 comments No comments