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

  • SEARCH
  • Home
  • 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 8392309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:29:08+00:00 2026-06-09T19:29:08+00:00

The Issue I need to maintain the state of a dynamically created table through

  • 0

The Issue

I need to maintain the state of a dynamically created table through a PostBack on an ASP page.

The Details

When a user accesses the page, a table of CheckBoxes is created based of information stored in a database. Basically, these CheckBoxes are laid out in a grid, checked/unchecked and enabled/disabled based off of information in the database. They’re also color-coded, but that’s not really relevant.

The dimensions of the grid, and the state of the checkboxes is determined at Page_Load. I have a class called DisplayWell which is just a TableCell which holds the CheckBox. There’s an empty Table on the page itself, and I loop through and add the DisplayWells. The user can then make edits to the state of the checkboxes, and a handful of TextFields, and click a button to save.

The problem, as I’m sure you know, is that fact that these dynamically created objects disappear after Page_Load: the server hands them off to the client and they’re destroyed. I need to be able to preserve the state of the table or the object array to be able to update the database.

Until now, I’ve used hidden fields to store information that I needed to persist across postbacks, but only for one or two variables, which really wouldn’t work in this case (typically we’re talking about 96 CheckBoxes, but it could be any number). I’ve read that you can store objects in the session variables, but will the state of the object register changes made on the client side? I’ve also heard that’s a bad idea.

Edit:
After testing it, changes are NOT registered – I got the same array back from the session variables.

FWIW, here’s Page_Load:

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {                
        if (Request.QueryString["Plate_INDEX"] != null &&
            Request.QueryString["Block_INDEX"] != null)
        {
            String sPIndex = Request.QueryString["Plate_INDEX"].ToString();
            String sBIndex = Request.QueryString["Block_INDEX"].ToString();
            if(-1 != Block_INDEX)
            {
                lblExpPlate.Text = "Edit a Solution";
                populateFields();
            }
            hfPlate_INDEX.Value = Plate_INDEX.ToString();
            hfBlock_INDEX.Value = Block_INDEX.ToString();                        
            createPlate();
            addToTable();                
        } // end queryString != null
    }
} // end Page_Load

private void createPlate()
{
    MTT_Plate_IO mpio = new MTT_Plate_IO();
    SqlDataReader plateReader = mpio.Get_Plate(Plate_INDEX);

    if (plateReader.Read())
    {
        r = (int)plateReader["Plate_Rows"];
        c = (int)plateReader["Plate_Columns"];
        hfPlate_INDEX.Value = plateReader["Plate_INDEX"].ToString();
        dwArr = new DisplayWell[r, c];
        for (int i = 0; i < r; i++)
        {
            for (int j = 0; j < c; j++)
            {
                dwArr[i, j] = new DisplayWell();
                dwArr[i, j].cb.Checked = false;
                dwArr[i, j].cb.Enabled = true;
            }
        } // end creation of plate                
    } // end plateReader
} //end createPlate();


private void addToTable()
{
    // create a header for the table
    TableRow header = new TableRow();
    TableHeaderCell blankCell = new TableHeaderCell();
    header.Cells.Add(blankCell); //blank cell to align with data

    // add numbers to top of plate
    for (int i = 1; i <= c; i++)
    {
        TableHeaderCell thc = new TableHeaderCell();
        thc.Text = i.ToString();
        header.Cells.Add(thc);
    }
    tblPlate.Rows.Add(header);

    //create the plate
    for (int i = 0; i < r; i++)
    {
        TableRow tr = new TableRow();
        TableCell rowHeader = new TableCell();
        rowHeader.CssClass = "style5";
        //add a letter to the beginning of the row
        String rowHeaderText = ((char)(i + 65)).ToString();
        rowHeader.Text = rowHeaderText;
        tr.Cells.Add(rowHeader);
        for (int j = 0; j < c; j++)
        {
            tr.Cells.Add(dwArr[i, j].tc);
        }

        tblPlate.Rows.Add(tr);
    }
}    
  • 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-09T19:29:09+00:00Added an answer on June 9, 2026 at 7:29 pm

    Thanks to the advise of Andrew-Barber, who I had hoped would show up and answer this question (you still can!), I figured out the solution:

    Create the object in the OnInit method and remove the if(!Page.IsPostBack) block, instead instantiating the object for every instance of the page. This happens earlier in the page’s life cycle, and persists the object in memory on server-side, allowing changes made client-side to be registered.

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

Sidebar

Related Questions

Here's my issue - I need to dynamically download several scripts using jQuery.getScript() and
I am dealing with an issue and need some expert advice on to achieve
I rarely use SQL and have a unique issue I need to solve. I
I need to issue multiple $.get requests, process their responses, and record the results
We have an issue where we need to modify keys for users that are
I am having an issue where I need to be able to specify the
My Problem My core issue is I need to start the gnome-keyring-daemon from c
I am using CodeFirst approach and struck with an issue where I need to
having the following XML sample document, I need to issue an XPath/XQuery expression to
I need to fix a issue for xss vulnerability. the code segment is below.

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.