Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabled textbox losses viewstate

I am dynamically generating the form based on the drop down selected. The form consists of fields (data entry for decimal values + few text fields). Have to add all the decimal values at the end and update the Total TextBox with that value. Total Textbox is disabled.

When I click Save button on the form after the user have entered their values, whole form is persisted in viewstate except the disabled textbox. When I enable the textbox, everything works fine. Mind you, I am dynamically generating the form and updating the value of the total textbox using javascript to calculate (adding all decimal fields).

P.S. I am doing everything right for persisting the viewstate.

So what has the enabled/disabled got bearing on the viewstate

like image 272
DotNetInfo Avatar asked Jun 11 '11 14:06

DotNetInfo


2 Answers

Basically, I added two statements to get it working.

txtBox.Attributes.Add("readonly", "readonly");
txtBox.Style.Add("color","gray");

When I used txtBox.Enabled = false, it didn't persist viewstate but did it alternatively using above two statements in my code-behind page

like image 72
DotNetInfo Avatar answered Sep 23 '22 22:09

DotNetInfo


Yes, disabled form element will not send it's value to server side, you can look request header. disabled element not appeared at "get" or "post" collection.

If you want set user can't edit it, you can set it as readonly.

like image 38
xling Avatar answered Sep 22 '22 22:09

xling