ViewState don't saved on a custom control

L

lirlir

Hi to all,

i have this problem:
my sample combine 2 components,

the first one is a simple aspx page (T1.aspx) with a
Button runat server and with the next code:

private void Page_Load(object sender, System.EventArgs e)
{
C1 c = new C1();

this.FindControl("Form1").Controls.Add(c);

}

the second component is a UserControl (C1.ascx) that i create dynamiclly like that:
protected override void Render(HtmlTextWriter writer)
{
TextBox txt = new TextBox();

txt.ID="txtSelectedParams" + UniqueID ;
this.Controls.Add(txt);

base.Render(writer);
}

the problem is that after postback the value on the textbox is gone....

please help me by let me know what am i doing wrong.

lirlir
 
T

Teemu Keiski

Hi,

adding TextBox at Render stage is too late in the Page lifecycle. Postback
data loading occurs first time between Init and Load and second time right
after Load, so if you want to get your TextBox's postback data loaded
automatically, it would need to be added to the Controls collection at Load
(at the latest). However, if you want or need to do it manually, you can
access it via Request.Form collection.

Here's more background information:
http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=391019
http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=285389
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top