Question about 'hiding' form controls

R

Rob Meade

Hi all,

I've got myself into a bit of a problem and I'm trying to dig my way back
out, in a) the quickest way due to project deadline and also b) best
approach.

I have a form which gets a set of document type properties from SQL Server,
these properties are used to create corresponding controls on the form, so
for example:

PropertyDisplayName : Surname
PropertyObjectName : txtSurname

In this very small example the "Surname" text would be displayed on the left
of the text box which would have the ID of "txtSurname".

There are currently 6 different document types - each with a set of
properties, some of the properties are common in each document type (like
surname for example).

My problem is that if my querystring does not contain the 'document type' I
dont know what type of form to give the user - therefore the form has a drop
down menu with all of the document types listed for them to select from -
this only appears if the querystring value is missing, if it is present,
then the drop down is replaced with a readonly text box with the name of the
document type in it.

What I need to do in the case of the querystring not containing a value for
the document type would be to change the controls on the form. This needs
to be achieve without a reload of the page.

Initially I was thinking that I could get all of the document types and
associated properties from the database in one go at the beginning, put each
document type into a seperate 'panel' and then show/hide the relevant
panel - my only probelm with this (untested) is that I also have validation
controls for each dynamically created control - the names for these are also
taken from the database - ie txtSurname would have the first 3 characters
dropped and then have vld added - creating vldSurname, I can foresee if I go
down this route 6 panels all sharing at least 1 control which is the same
(lets say surname) - and therefore having 6 txtSuranmes and 6 vldSurnames -
surely this will cause some form of problem as the names wont be unique.

My next thought was perhaps to create the one display with all of the
properties on it regardless of which document type they belong to and set
them all to visible = false at the start - then if they are needed by the
document type change their visible status to true. My question here is
whether or not if you set a control to visible = false whether it still gets
submitted when the form is submitted?

Any information or suggestions on this would be appreciated - if I had more
time for this I may go back and change somethings which may remove this
issue - however time has nearly run out so I need a 'best solution for now'
kinda approach.

Regards

Rob
 
M

Mark Rae

Any information or suggestions on this would be appreciated - if I had more
time for this I may go back and change somethings which may remove this
issue - however time has nearly run out so I need a 'best solution for now'
kinda approach.

Not very fashionable these days, but you might be able to achieve what you
want with a FRAMESET.
 
R

Rob Meade

...

Hi Mark - thanks for your reply.
Not very fashionable these days,

you mean the 'approach'?
but you might be able to achieve what you want with a FRAMESET.

as in the HTML frameset...I'd never live it down if I started using frames
within my applications....

Would the control.visible = false not simply remove the control from the
rendered page?

Regards

Rob
 
R

Rob Meade

Hi Mark, I just re-read what you'd reply with - like duh me...I see what you
are saying now - ie, Framesets are not overly fashionable....

lol...need more sleep! :)

Rob
 
M

Mark Rae

Rob,
you mean the 'approach'?
Yes.


as in the HTML frameset...I'd never live it down if I started using frames
within my applications....

I know what you mean... :)
Would the control.visible = false not simply remove the control from the
rendered page?

If it's a server-side control, yes it would.
 
M

Mark Rae

Hi Mark, I just re-read what you'd reply with - like duh me...I see what you
are saying now - ie, Framesets are not overly fashionable....

lol...need more sleep! :)

LOL!
 
R

Rob Meade

...
If it's a server-side control, yes it would.

Hi Mark,

yep - they are all server side controls, I just wondered how far the
'ignore' affect kinda works - ie, if I set them to false are they not even
in the HTML code on the page, or more likely, are they in the HTML but have
style which hides them? my concern is that although I hide a whole table
row which has a text box and a validator control in it - would the validator
still be fired for that control even though the user has no way to put any
info in the box...this might cause a bit of a problem etc..

Reg's

Rob
 
M

Mark Rae

yep - they are all server side controls, I just wondered how far the
'ignore' affect kinda works - ie, if I set them to false are they not even
in the HTML code on the page, or more likely, are they in the HTML but have
style which hides them?

Nope. Setting a server-side's visible property to false will mean that
ASP.NET will not render the HTML for that control.
my concern is that although I hide a whole table
row which has a text box and a validator control in it - would the validator
still be fired for that control even though the user has no way to put any
info in the box...this might cause a bit of a problem etc..

Gosh. To be truthful, I don't actually know! However, I would strongly doubt
it...
 
R

Rob Meade

...
Nope. Setting a server-side's visible property to false will mean that
ASP.NET will not render the HTML for that control.

Marvellous - I think.....however....just thinking this through.....if I was
therefore to set all of the form controls to hidden when the page loads
(assuming I've not received the required value in the querystring) - if I
then had an selected item changed event on the drop down box - could I use
that to then 'show' the controls back on the page? The only way I see that
working is if the page was reloaded - as you have mentioned - if it doesn't
render the html at all then it would have to run off and come back again
wouldn't it?
Gosh. To be truthful, I don't actually know! However, I would strongly
doubt it...

If the html doesn't get rendered then this wouldn't be a problem - but of
course raises the issue of the page perhaps having to be reloaded when the
drop down value is changed...

Thanks for your help Mark - I'll give it ago when I get 5 mins (he says
optomistically as if I could actually do this in 5 mins!) - and let you know
what happens!

Reg's

Rob
 
M

Mark Rae

Thanks for your help Mark - I'll give it ago when I get 5 mins (he says
optomistically as if I could actually do this in 5 mins!) - and let you know
what happens!

I'd be interested to know the outcome, as what you're trying to do is
something I've never had a need to do!
 
R

Rob Meade

...
I'd be interested to know the outcome, as what you're trying to do is
something I've never had a need to do!

Hi Mark,

I will do - probably be next week now before I get an opportunity try it.

Reg's

Rob
 

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,770
Messages
2,569,583
Members
45,072
Latest member
trafficcone

Latest Threads

Top