Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a created a dynamic table with dynamic buttons as cells and save button is also dynamic,on page postback or on any button click table disapears, how to retain it?
Posted

dynamic controls will disappear after postback, to solve that issue rebind after postback.
for example

if (!IsPostBack)
        {
            Button button = new Button();
            button.ID = "Button1";
            PlaceHolder1.Controls.Add(button);
        }
        else
        {
            if (PlaceHolder1.FindControl("Button1") != null)
            {
                //bind your control
                Button button = new Button();
                button.ID = "Button1";
                PlaceHolder1.Controls.Add(button);
            }
        }
 
Share this answer
 
For a databound table (or similar) you'll need to record how many rows you've created in viewstate and recreate them in the Page Load event.

One thing to watchout for is making sure that the uniqueid for each control is the same after the postback, otherwise the viewstate wont be restored properly.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900