Alex Alex - 1 year ago 62
ASP.NET (C#) Question

JQuery Set Value of asp textbox and pick up value when posted back to the server

I have an asp textbox, declared like this in the code:

<asp:TextBox runat="server" ID="txtEmail" autocomplete="email" />

Which looks like this on screen when I have added content to the input:
enter image description here

and looks like this in Chrome developer tools:
enter image description here
even when I have added content to it (eg content does not show up in developer tools).

Next, I have this textbox:

<asp:Textbox id="AddressInformation" Text="" runat="server"/>

and I add content to it using JQuery, by doing the following:

$('#<%= AddressInformation.ClientID %>').text(AddressString);

and then it is emplty on screen - like this:
enter image description here

and looks like this in developer tools (eg content does show up in developer tools):
enter image description here

The problem is, that when I postback, I want to be able to to read the value from the AddressInformation textbox in the C# code, but this does not work.

I am trying to do so using:


but this does not work as it normally would - it just returns an empty string.

I have looked for other options on AddressInformation, such as inner text, but cant find one.

I suspect the issue is to do with the fact that I am using
to populate this, and that is why the address and email look different in developer tools. I note that the email value does not show in developer tools even when the input has a value, but the address value does show up.

I am sure it is possible to do what I am trying, as it is essentially the same thing as .net does on the postback - I just cannot work out how to do it - any ideas?

Answer Source

In the following line:

$('#<%= AddressInformation.ClientID %>').text(AddressString);

Instead of populating using .text(), populate it with .val()

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download