get a disabled textbox value by clientid server side


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.

I need to get the value of a text box that is disabled with javascript. Ultimately I will use the value as a parameter of a SQL insert statement. I have read that I need to get the value by doing something like this:


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


in serverside.

you can refer the link

.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
End Sub

The best way I was able to post the value of the textbox, while still not allowing the user to change the textbox's text, was to set the readonly attribute to true progamatically on PageLoad. This way the textbox is "disabled" to user input, yet .NET4 will post the texbox's value set by the javascript. I was able to access the textbox value as I usually would on the server side by accessing the .text property of the textbox.

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.


Need Your Help

how do I display hex data in well aligned(like as tabular format) in windows application

c# winforms

I want to display the contents of bbbb.txt file to hex format into richTextBox2.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.