Hidden Text boxes

  • Thread starter Thread starter DanWeaver
  • Start date Start date
D

DanWeaver

Due to the lack of persistence in a listbox element across postbacks I
have been forced to use textboxes to gather eg removed items (removed
via a javascript) so that the listbox can be repopulated on postback
amongst other things.

I now find (stupidly I didnt test this before) that when an asp text
box is invisible ie visible= false the client side sript that writes
to it shows an error- ie cant write to it. I have tried adding an
attribute ie textbox.Attributes.add of type hidden but to no avail.

Any clues?

Dan
 
The correct way is to use a hidden input control, as another poster said.

There is still a way of hiding any control and still have it available on
client side and on postbacks. That is to hide it with a css rule
display:none.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
 
Due to the lack of persistence in a listbox element across postbacks I
have been forced to use textboxes to gather eg removed items (removed
via a javascript) so that the listbox can be repopulated on postback
amongst other things.

I now find (stupidly I didnt test this before) that when an asp text
box is invisible ie visible= false the client side sript that writes
to it shows an error- ie cant write to it.

That's right - controls whose Visible property is false do not actually get
rendered down to the client...
I have tried adding an attribute ie textbox.Attributes.add of type hidden
but to no avail.

You can add pretty much any attribute you like to controls but, unless it's
an attribute which the browser recognises (e.g. onclick, onblur, style etc),
it will simply be ignored client-side.
Any clues?

http://msdn2.microsoft.com/en-au/library/system.web.ui.webcontrols.hiddenfield.aspx
 
Back
Top