disabled dynamically added controls and postback

  • Thread starter Thread starter djk
  • Start date Start date
D

djk

Hi all!

Please help me with the following real-trouble:

- I have dynamically created controls on page
- Everything works unless I set for some controls .Enabled = false

In such a case stored value for the disabled control is lost (not sent by
MSIE back to server).

But it works for static controls.

What's wrong?

Thanks a lot

djk
 
Djk,
I whipped up a small example, and the key is adding the dynamic control
to the page prior to assigning any values. Values that are assigned before
the control is a part of the page will be lost. Here is some sample code
that will exhibit the behavior you describe:
TextBox txt = new TextBox();

if(!IsPostBack)

{

txt.Text = "test value";

}

this.Form1.Controls.Add(txt);

if(txt.Enabled)

txt.Enabled = false;

else

txt.Enabled = true;


The following code will behave properly (retain values):
TextBox txt = new TextBox();

this.Form1.Controls.Add(txt);

if(!IsPostBack)

{

txt.Text = "test value";

}

if(txt.Enabled)

txt.Enabled = false;

else

txt.Enabled = true;


Notice that the only change was adding the dynamic control before the value
was assigned.

Best regards,
Jeffrey Palermo
 
Back
Top