Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8715209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:47:33+00:00 2026-06-13T05:47:33+00:00

General Problem: I’m trying to create something similar to this: The user can select

  • 0

General Problem:

I’m trying to create something similar to this:

enter image description here

The user can select a product from the dropdown, click add, and the result is another product
row being added underneath in the “Product Added” section. A “Product Descriptor” must be selected for each product that has been added via the dropdown in each row. Only when the user clicks the “Submit” button does each of the product rows get inserted to the database.

Question:

What is the best way to persist the product selections between Postbacks?

I’m not worried about persisting the “Product Descriptor” selections, I believe I can do that. My main concern is finding the best way of storing these temporary selections before they are saved to the database.

My current approach:

The way I’m doing it now is to manage list of ProductListItem objects in the viewstate. This list is bound to a ListView that displays the added products.

Private Property SelectedProductList As List(Of ProductListItem)
        Get
            Return CType(ViewState("SelectedProductList"), List(Of ProductListItem ))
        End Get
        Set(ByVal value As List(Of ProductListItem ))
            ViewState("SelectedProductList") = value
        End Set
End Property

The ProductListItem class:

<Serializable()>
Public Class ProductListItem

    Public Property ProductID As Integer
    Public Property ProductName As String

    ' ProductDescriptor class represents Product Descriptor (details omitted)
    Public Property Descriptor As ProductDescriptor 

    ' Constructor omitted

End Class

The Add Button Click handler:

 Protected Sub btnAddProduct_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddProduct.Click

        SelectedProductList.Add( New ProductListItem(...) )
        ProductListView.DataSource = SelectedProductList
        ProductListView.DataBind()

  End Sub

I’m thinking to use the Session instead of the Viewstate here, because I have two other similar situations on the same page, where I’m keeping lists of objects in the viewstate, and I’m worried about the Viewstate getting corrupted or getting too big. What do you think?

Thanks for your time!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T05:47:36+00:00Added an answer on June 13, 2026 at 5:47 am

    The viewstate is the solution, because if you save them on the session you have this main problems:

    • The session can be lost before the user press submit
    • The user can open more than one windows with the same content, but the session will be the same, and a big mess will happens.

    Now, on the viewstate to avoid to be too big you can do the following (all together):

    • Compress it
    • Split it.
    • Optimize the what you write on it, eg you can write on there 100 records of DropDownList, or just the sql select that gets that 100 records.

    You can also create a class that hold all the data together, optimize it, and save it on viewstate. On every page load, using this class you recreate the page form.

    How to optimize class for viewstate

    More on viewstate optimization:

    Determine size of ASP.NET page's viewstate before serving page
    http://www.codeproject.com/Articles/14733/ViewState-Compression
    http://www.hanselman.com/blog/ZippingCompressingViewStateInASPNET.aspx
    http://www.bloggingdeveloper.com/post/How-To-Compress-ViewState-in-ASPNET-20-ViewState-Compression-with-SystemIOCompression.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know the general problem of Can't create handler inside thread that has not
The main problem I'm having is pulling data from tables, but any other general
I am looking for a general and complete solution to this common problem! I
Update: After some more reading I see that this problem is totally general, you
I have this general problem in design, refactoring or triage: I have an existing
In Windows Forms programming, I have this general problem. When the page is loading
I am using Delphi, but this is a simple and general problem: I'm doing
This is an example of my general problem: I have different implementations of ITextSearcher
This should be a general problem, i've searched but couldn't found any solution yet,
This is a fairly general problem I am having here, so I figured I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.