Dynamic Control . does not work until first postback..
-
Ok, here is my design idea.. Textbox is only being used as a test at this point, i have a custom control I will replace it with once I get it working with a basic textbox. I have a list stored in a serialized viewstate. I have a button that when you click it, it creates a item in the viewstate with the buttons id. I have in my PageLoad, code to create a button for each id in the viewstate upon each load.. My view state object..
namespace CusControls
{
[Serializable]
public class userPramBaseState
{
private string _ID;
public string ID
{
get { return _ID; }
set { _ID = value; }
}
}
}Now, this code works, but only after first click.. then all the textboxes retain their values... but the first click.. does nothing.. appears too anyways... but it just does something but nothing works..
using CusControls;
public partial class run_reportV2 : basePage
{const string cCusParamList = "CusParamList"; public List TmpParamList { get { if (ViewState\[cCusParamList\] == null) ViewState\[cCusParamList\] = new List(); return (List)ViewState\[cCusParamList\]; } } protected override void OnInit(EventArgs e) { base.OnInit(e); Master.userObj = user; } protected override void OnLoad(EventArgs e) { base.OnLoad(e); InitCustomControls(); } public void InitCustomControls() { if (TmpParamList != null) foreach (CusControls.userPramBaseState x in TmpParamList) { TextBox tmpctrl = new TextBox { ID = "CUSCTRL" + x.ID }; CusParamControls.Controls.Add(tmpctrl); } } public void btnAdd\_Click(object sender, EventArgs e) { int locid = TmpParamList.Count+1; //store control ids into ctrl collection.. CusControls.userPramBaseState y = new CusControls.userPramBaseState(); y.ID = "CUSCTRL" + locid; TmpParamList.Add(y); }
}
=)