|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to Persist Dynamic Rows within WebControls.Table?I have made a System.Web.UI.WebControls.Table called Table1. I can add a few rows in the VS2005 Designer and those rows do indeed persist between web page views. I can even do a Table1.Rows.Clear() and these rows go away, as expected. The problem is that when I add rows dynamically within my aspx.cs source code (via Table1.Rows.Add(row), the added rows appear once and only once. When I refresh the page, the rows I added dynamically are gone from the web page. I turned on EnableViewState=true for Table1, for every Row within Table1, for every Cell within every Row, and for every Control within every Cell. The dynamically added rows do not appear the second time, after a refresh. I have other web controls that work fine, e.g., CheckBoxList, that persist their dynamically added data (in this case via Items.Add()). What am I doing wrong? Thanks. hi, you must let the same code you used to add the dynamic rows re-execute
after a postback. You must know that after your page is rendered to the client, it is torn down and destroyed, so a postback to your page will start reconstructing all items from scratch. Initially when you had the rows added via the vs.net designer, it adds the rows declaratively in your .aspx so it is being rebuilt again, getting the information of the rows to construct from there. Now that you are doing this dynamically, you should allow the same code(the code that adds your dynamic rows) to re-execute after a postback, and a bit early in the pages life cycle. Some obvious mistakes are not to wrap that part of your code in an if ispostback check, and if you are adding the rows in the click of a button, then make sure you set some flag in viewstate, that way you can re-execute the same code for reconstructing the rows again, based on a condition. This reconstuction wont make you lose whatever state information that was already present before, since viewstate will be reloaded back into the control in question after the reconstruction. If you still have problems then post your source code. Some good references for you on msdn : http://msdn2.microsoft.com/en-us/library/hbdfdyh7.aspx http://support.microsoft.com/kb/317794/EN-US/ Regards, Alessandro Zifiglio http://www.AsyncUI.net <samtil***@gmail.com> ha scritto nel messaggio Show quoteHide quote news:1154454681.473227.204880@i3g2000cwc.googlegroups.com... > Team: > > I have made a System.Web.UI.WebControls.Table called Table1. I can add > a few rows in the VS2005 Designer and those rows do indeed persist > between web page views. I can even do a Table1.Rows.Clear() and these > rows go away, as expected. > > The problem is that when I add rows dynamically within my aspx.cs > source code (via Table1.Rows.Add(row), the added rows appear once and > only once. When I refresh the page, the rows I added dynamically are > gone from the web page. > > I turned on EnableViewState=true for Table1, for every Row within > Table1, for every Cell within every Row, and for every Control within > every Cell. The dynamically added rows do not appear the second time, > after a refresh. > > I have other web controls that work fine, e.g., CheckBoxList, that > persist their dynamically added data (in this case via Items.Add()). > > What am I doing wrong? > > Thanks. >
Events fired from dynamically created controls-VB.net
Set property in user control Dynamic button event not firing C# Correct place to add an event handler in code? Literal control rendering empty Referencing a parent control from a child? Adding layout elements within custom control customizing the dropdown menu of combo box in asp.net dropdownlist System.Data.SQLClient |
|||||||||||||||||||||||