Search code examples
jqueryasp.netformview

Can't get value of textbox when inside formview using jquery


I am trying to get the value of a textbox that is in an asp.net formview using jquery but have not had much luck.

Value I am trying to get is here:

<label class="labelWidth120" for="txtPhysicalAddrLine1">
Address Line 1:</label><asp:TextBox ID="txtPhysicalAddrLine1" CssClass="alphanumeric address" runat="server" Text='<%# Eval("primaryAddress1") %>' MaxLength="50" OnTextChanged="ValueChanged" TabIndex="1"/>

jQuery I am using to try and get at it is:

var a = $('<%=fvSubscriber.FindControl("txtPhysicalAddrLine1").ClientID %>').val();
alert(a);

I am not getting any js error,"a" is not null and the alert box is empty. Where am I going wrong


Solution

  • you are forgetting the # in your jquery selector... if I had a dollar for everytime I've done that... ;-)

    var a = $('#<%=fvSubscriber.FindControl("txtPhysicalAddrLine1").ClientID %>').val();
    alert(a);