hai friends!
My user control will create some of the dynamic controls in page
That dynamic controls text values, i will get by using the LoadViewState() method by using viewstate
In normal aspx page ,i tested this feature viewstate works well and i get all the dynamic controls values when each button click event postback
But in mojoportal,viewstate does not works properly,viewstate gives empty values when first button click event,next it will gives the previous dynamically created textbox values,not giving last dynamiclly created values in viewstate.
I am useing thhis code:
protected override void LoadViewState(object savedState)
{
//MAKE SURE TO LEAVE THIS CALL TO THE BASE CLASS
// this is what loads the ViewState into memory
base.LoadViewState(savedState);
foreach (string txtID in ControlsList)
{
TextBox txt = new TextBox();
txt.ID = txtID;
txt.Visible = false;
DynamicControlsHolder.Controls.Add(txt);
}
}
private List<string> ControlsList
{
get
{
if (ViewState["controls"] == null)
{
ViewState["controls"] = new List<string>();
}
return (List<string>)ViewState["controls"];
}
}
//call this function in pageload
int i = 0;
foreach (Control ctl in DynamicControlsHolder.Controls)
{
if (ctl is TextBox)
{
TextBox txt = ctl as TextBox;
if (ctl != null)
{
dynamic[i] = txt.Text; // Here it gives the previous values
i++;
}
}
}
Please help me!
Thanks,
Nalini.