Changing controls after an event

  • Thread starter Thread starter Adrian Parker
  • Start date Start date
A

Adrian Parker

I have a form with some controls on it, one of them has an auto postback
onchange. So the postback occurs but before the event fires, all the
controls are recreated. so my question is, if the event requires you to
replace a control with another type, e.g. replace a textbox with a date
control, how do I get it to redo the form with the new control, force
another postback ? if so , how ?

Thanks
Adrian Parker
 
Adrian,

The easiest way is to prepare all controls in design time and switch their
visibility on events.

Eliyahu
 
Ah, can't do that as the forms are gernerated from data.. I just have some
code that's called for all forms so that I can put any special coding for
onchange in if needed.
 
Not clear. What is generated from data? Server controls? Html elements? How?

Eliyahu
 
You're going to need to have some state information somewhere that tells
your server code what controls to recreate upon postback. You should recreate
these controls in Page_Init (if it's directly in the Page) or override CreateChildControls,
or if it's an ASCX then Page_Load is also a fine place to recreate these
controls.

-Brock
DevelopMentor
http://staff.develop.com/ballen
 
Ok, lets explain how it works at the moment..

We have data that contains the SQL for the select and update statements, as
well as a list of the fields to display on a form with their display types
e.g. dropdown, text, date etc. these control definitions are stored in an
array. The user control just contains a table with 2 columns.. then we
add a row for each field with a text label in the left column and the input
control on the right.. or visa-versa for a right to left culture. When we
create the input controls we set the auto postback if we nned to check the
changed event.

As an example, say we have a dropdown control that decides what comes next,
a numeric input textbox or a date control. Initially the textbox control is
displayed. So when the dropdown changes, it does a postback and all the
controls are re-created (including the textbox) then the dropdown change
event fires.. at which point you decide that the new dropdown value means
that you don't want the textbox anymore, you want the date input control.
How can I get rid of the textbox and create the date one instead.

Thanks
Adrian
 
Back
Top