Dynamic controls values not properly assign to viewstate when postback

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
5/3/2012 8:26:09 AM
Gravatar
Total Posts 26

Dynamic controls values not properly assign to viewstate when postback

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.

 

You must sign in to post in the forums. This thread is closed to new posts.