1

Ok, I've searched for a while but still haven't found anything that fixes my issue.

I am updating a readonly Textbox in ASP.NET with JQuery after the selection of radio buttons. The value shows up and everything seems to work from an HTML standpoint but Address.Text in the code behind returns nothing.

Also, I've posted all my attempts in the JavaScript section, I know I should only need one of these to update what I'm trying to update.

HTML:

<asp:TextBox class="form-control form-inline" runat="server" ID="Address" placeholder="Populates based off account type" readonly="true"/>

JavaScript:

$(document).ready(function () {
    $('input[type=radio]').click(function () {       
        $('#Address').attr("value", $(this).val());
        $('#Address').attr("Text", $(this).val())
        $('#Address').val($(this).val());
        $('#<%= Address.ClientID %>').val($(this).val());
        $('#<%= Address.ClientID %>').text($(this).val());
        $('#AccountType').val($(this).val());
    });     
});

ASP.NET

ClientScript.RegisterStartupScript(GetType(), "myalert", "alert('Address: " + Address.Text + "' );", true);

Thanks in advance to anyone that can help me out.

Codeman27
  • 13
  • 4

1 Answers1

1

When you set the ReadOnly property to true of an ASP.NET TextBox, it basically assumes the value can't be changed clientside and won't post changes back. Try setting it readonly like:

textBox.Attributes.Add("readonly", "readonly");

Additional SO post for reference.

Community
  • 1
  • 1
kman
  • 2,184
  • 3
  • 23
  • 42
  • 1
    You are awesome! I'd up vote you but it looks like I'm too new to do that. Thank you! My head hurts from pounding it against the wall for these last couple of hours. – Codeman27 Apr 01 '17 at 20:26