Click here to Skip to main content
15,888,579 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Disabling viewstate of textbox does not effect the textbox value. The value will retain after post back no matter you disable viewstate or not.
so my question is textbox do use viewstate or not?

update
As I have recevied some answer which probably means that value maintain because server fill back the values to textbox thats why values retain. if this is the case then why not html textbox values maintained?
Posted
Updated 13-Apr-15 4:22am
v2

When the TextBox control is enabled, visible, and not read-only, it renders a form element (either <input type="text" > or <textarea>). These elements will send their values back to the server when the form is submitted. The control loads that posted value, regardless of whether view-state is enabled.

If the control is not enabled, not visible, or read-only, then the value will not be posted back to the server. In this case, the control will only remember its value if view-state is enabled.

If view-state is disabled, the TextChanged event will not fire.
 
Share this answer
 
Comments
Muhamad Faizan Khan 13-Apr-15 9:39am    
means the value again fill after the form submission
Richard Deeming 13-Apr-15 9:42am    
Yes, if the control is enabled, visible, and not read-only, it will retain its value on post-back, even if view-state is disabled.
Muhamad Faizan Khan 13-Apr-15 10:17am    
but why html element doesnot retain the values as control loads the posted values
Richard Deeming 13-Apr-15 10:25am    
By "HTML element", do you mean an <input type="text" ...> which doesn't have runat="server" on it? That's not a server control, so it doesn't execute any code on the server, and therefore cannot retain its value.
Praveen Kumar Upadhyay 13-Apr-15 10:30am    
+5.
Ahmm,

The reason is because in case of TextBoxes, the values gets submitted to the server on every postback and are available in the Request.forms collection.

This means that despite of the viewstate being disabled for textboxes, the value is fetched from the Request.forms collection and displayed.

Cheers,
C
 
Share this answer
 
Comments
Muhamad Faizan Khan 13-Apr-15 10:18am    
but why html element doesnot retain the values as control loads the posted values
Joezer BH 13-Apr-15 10:55am    
Since it does not contain the runat="server" property by default. If you add this property (and provide an ID to the control so that it can be referenced in the C# code) it will.
Yes ,it will use view state,If you Disable the View state ,it doesn't retain the value after post back.

If the page get post back ,the textbox data will be loss.

Here is the Good article about your Question .Kindly read this

http://www.c-sharpcorner.com/UploadFile/225740/what-is-view-state-and-how-it-works-in-Asp-Net53/[^]
 
Share this answer
 
Comments
Richard Deeming 13-Apr-15 9:29am    
Not quite true - if the control is enabled, visible, and not read-only, the value will be sent back to the server every time the form is submitted.
Joezer BH 13-Apr-15 10:13am    
Right you are Richard, tnx for the notice!
I've created a second solution.
Muhamad Faizan Khan 13-Apr-15 9:36am    
problem is textbox maintain that's why asked this question

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900