disabled dynamically added controls and postback

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
 
J

Jeffrey Palermo [MCP]

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
 

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,754
Messages
2,569,525
Members
44,997
Latest member
mileyka

Latest Threads

Top