get a disabled textbox value by clientid server side asp.net
I guess in simpler terms what I am trying to do is get the post value of a disabled textbox to use in a SQL insert statement when the form is posted.
my understanding is that this would only return the html rendered value of the control's ID. how do I actually retrieve the value of the text in the textbox?
ASP.NET VB is the language I am working with
Textboxvalue as string = textboox1.text
If your form requested by post method, You can get the value of form control by syntax
you can refer the link http://msdn.microsoft.com/en-us/library/ms525985%28v=vs.90%29.aspx
.NET controls maintain their state on postbacks, there will be a TextBox object called EnterDateTXT available:
Dim txt as String = EnterDateTXT.Text;
What we do when retrieving the fields from the form, is execute the following recursive method. This takes care of readonly and disabled textboxes.
Because this method updates the textbox's Text property, no other code has to be concerned about the client-side state of the control:
''' <summary> ''' If a TextBox is marked as readonly, its value will not be updated into the server-side textbox control even though they are persisted. ''' This method copies the values from the Request.Form into textbox.text for all readonly textbox controls. ''' </summary> ''' <param name="cControls"></param> ''' <remarks></remarks> Private Sub RetrieveReadOnlyTextBoxValues(ByVal cControls As ControlCollection) ' Exceptions are handled by the caller For Each oControl As Control In cControls If TypeOf oControl Is TextBox Then DirectCast(oControl, TextBox).Text = Request.Form(oControl.UniqueID) End If If oControl.HasControls Then Call RetrieveReadOnlyTextBoxValues(oControl.Controls) End If Next End Sub
my Understanding is that .NET preserves the state of the postback, and if the textbox is set to enabled=false or readonly=true then .NET assumes the values of these cantrols cannot be modified, and will not post the values. by setting enabled=false or readonly=true on load, the postback state allows you to retrieve the text value
A disabled control does not get posted back to the server necessarily. I think that's the browser, and not the server doing that, but not 100% sure. Anyway, if you hide it, or make it readonly, it should work fine. Setting Enabled="false" on the server does not always mean disabled="disabled" on the client; sometimes, when you disable a control, it renders much differently. It really depends on the control.