How to set readonly property of a textbox in javascript
asp.net, javascript
Solution
You can set an ASP.NET textbox readonly through javascript. Here is how:
<script type="text/javascript">
function setReadOnly(){
var textbox = document.getElementById("TextBox1");
textbox.readOnly = "readonly";//readOnly is cese-sensitive
}
<body onload=" setReadOnly ()">
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</div>
</form>
</body>
Hope it'll help you.
Problem
i have a textbox whose property i need to set as readonly... how to set that? I tried ``` document.getElementbyid("txtbox").readonly=true; document.getElementbyid("txtbox").disable=true; document.getElementbyid("txtbox").setattribute("readonly","readonly"); ``` all these are not working for me. Disable is working but that is passing the control values as null to the database...again that is a problem for me..