ViewState don't save......

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
 
H

Hans Kesting

lirlir said:
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

You need to add the textbox in the Page_Load event, that is where it will get it's value.

Hans Kesting
 
L

lirlir

Hi Hans,

I changed the creation of the textbox from the Render to the PageLoad,
but than i got 2 controls on the screen.

i want to have only one control that saves its viewstate.

lirlir
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top