Thanks Martin,
I had seen the KB article but hadn't seen the User Interface Application
Process Block stuff. What it, and other articles on Dynamic Controls, gloss
over is the requirement to create the dynamic controls each time around.
I had come to the conclusion that all dynamic controls had to be created
every time, through trial and error, and it makes sense when you consider
the stateless nature of the beast. I was hoping that there was another way
as it means that the 'previous' controls have to be recreated to allow the
entered data to be accessed, presumably these will then have to be removed
before the 'next' set of controls are added to the page.
I also found that while I can initially create the controls in a button
click handler, the only way to access the control on postback is to create
them in the Page_Load or InitializeComponent functions. Presumably this is
so that the data from the ViewState can be applied to them.
Sounds like a good job for a state machine, which is presumably what the
User Interface Application Process Block stuff implements.
Bas
"Martin Marinov" <me********@mecrossroad.bg> wrote in message
news:OY**************@TK2MSFTNGP12.phx.gbl...
You have to recreate controls every time you visit the page ( with or
without postback). Take a look at this article
http://support.microsoft.com/default...b;EN-US;317794
also for creating wizard you can check the User Interface Application
Process Block here :
http://msdn.microsoft.com/library/de...a/html/uip.asp
Regards
Martin
"Bas Groeneveld" <no****@nospam.com.au> wrote in message
news:31*****************@news-server.bigpond.net.au... I am developing an ASP.NET application part of which consists of a data
entry wizard defined by entries in a data table - ie the controls on
each page of the wizard are determined by definitions in the table.
I know that I can dynamically add controls (eg a textbox) to the page
controls collection of a web form in a server event which will then be
rendered onto the form, as in the following snippet:
System.Web.UI.WebControls.TextBox tbTest = new
System.Web.UI.WebControls.TextBox();
tbTest.ID = "tbTest";
tbTest.Text = "Test Textbox";
tbTest.EnableViewState = true;
tbTest.Style["Position"] = "Absolute";
tbTest.Style["Top"] = "35px";
tbTest.Style["Left"] = "150px";
this.Controls.Add(tbTest);
The problem I have is on the subsequent postback. The control
dynamically added to the page controls collection is no longer accessible when the
page is posted back. ie the following code does not work:
if (this.FindControl("tbTest") != null)
lblMessage.Text = ((TextBox)(this.FindControl("tbTest"))).Text;
The only way I can get it to work is to create the control again on
postback in the page_load event:
if (IsPostBack)
{
System.Web.UI.WebControls.TextBox tbTest = new
System.Web.UI.WebControls.TextBox();
tbTest.ID = "tbTest";
tbTest.Visible = false;
this.Controls.Add(tbTest);
}
If I do this the control and any text entered can be accessed.
However this means that my page_load event has to know to add the same
dynamic controls as were added dynamically in another event (eg Next
button click) and then I need to delete these controls before I dynamically
create the controls needed for the next step of the wizard.
Is this the only way to handle this, or am I missing something obvious?
Thanks
Bas
--
==========================================
Bas Groeneveld
Benchmark Design System and Software Engineering
PO Box 165N, Ballarat North, VIC 3350
Phone: +61 3 5333 5441 Mob: 0409 954 501