Changing controls after an event

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
 
E

Eliyahu Goldin

Adrian,

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

Eliyahu
 
A

Adrian Parker

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.
 
E

Eliyahu Goldin

Not clear. What is generated from data? Server controls? Html elements? How?

Eliyahu
 
B

Brock Allen

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.
 
A

Adrian Parker

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
 

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,776
Messages
2,569,602
Members
45,182
Latest member
BettinaPol

Latest Threads

Top