Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post May 04, 2007 04:08 PM by JoshStodola
May 04, 2007 02:12 PM|LINK
This all works fine ...
namecontrol.disabled = true;
The problem is when the form does postback, I can't read the value of the textbox because it's disabled. I've been reading that disabled controls do not retain viewstate and as a result their values are not sent to the server on postback. A possible solution
would be to have a second textbox on the form that is hidden (and not disabled) so that when the form posts back to the server I can read that value, but i would rather not do that. Seems a little hackish and I would like to find a way to use just one textbox
Furthermore, it seems that if i was to set the enabled property of the textbox in serverside vb.net, the value would be retained on postback, but I cannot do that because the textbox becomes disabled clientside when a selection is made.
Any help would be great!
May 04, 2007 03:26 PM|LINK
namecontrol.style.display = 'none';
Hope this helps! Don't forget to mark the most helpful post(s) as Answer for the sake of future readers. Thanks!
May 04, 2007 03:33 PM|LINK
May 04, 2007 03:35 PM|LINK
May 04, 2007 03:40 PM|LINK
Well, i need to allow the user to manually enter/type a value (a company name) too. If they choose from the dropdown though, i check if the selected company is "registered". if so, i need to lock the textbox to prevent them from changing the value selected
from the dropdown.
The dropdown is just a panel that shows/hides on the form using ajax.
May 04, 2007 03:45 PM|LINK
Well, this is what I had in mind. You have a textbox AND a label. By default, your label has display:none. When you want to make it read-only, set the textbox display to none, and set the label display to block. Then put your value in the label. You
can then switch back and forth when necessary based on the drop down selection.
Hope this makes sense to you, let me know if you need help.
May 04, 2007 03:56 PM|LINK
ok, thanks for the info. i'll give it a shot and see how it works.
if i had the textbox control on the client like ...
<input type="text" id="txtTest" runat="server" />
how can i add the attribute readonly="readonly"? i'm just wondering if this would prevent the user from making changes to the textbox, but still post back the value to the server.
do i just use document.getelementbyid('txtTest').setAttribute("readonly", "readonly")
if so i don't think it works. oh wel, thought i would give it a shot ....
May 04, 2007 04:08 PM|LINK
Also, you dont need to call setAttribute for readonly, becuase there is already a property setup for that (just like disabled):
document.getElementById('txtTest').readOnly = true;
I hope you can get your issue resolved.