0
votes

My question is i am making a textbox readonly during the page load and i have edit button . when they click the edit button i have to make it editable i.e make readonly=false using javascript. Note : I have to use readonly property not disabled because disabling is making the content not readable look wise and also i have to readonly=true/editable using javascript.It is mandatory because the control is in a dialog and i dont want a postback.I tried the following code.It is throwing error.readonly object is not defined.

<input type="button"  id="hypJobDetailEdit" value="EDIT" id="btnedit" class="outlook-button" style="width: 85px" />

<asp:TextBox ID="txtrequestedby" runat="server" Width="150px" ReadOnly="true" />

javascript

<script>

$(document).on("click", "[id*=hypJobDetailEdit]", function () {   
     document.getElementById("MC_txtrequestedby").readOnly = false;    
});

</script>
2

2 Answers

0
votes

The ReadOnly state of your ASP.NET control is handled on the server. So your JS code has no ability to directly affect it. Changing ReadOnly to False, then, typically happens on the server via a postback. There may be some way to do it via a [WebMethod] in your code behind, but I'm not sure if that'll properly influence the ViewState or not.

0
votes

This change the readonly property to false:

$('#hypJobDetailEdit').on('click', function () {   
     $('#txtrequestedby').prop('readonly',false);   
});