Friday, 14 February 2014

How to make Asp.net Textbox Readonly in JavaScript

Solution:
script type="text/javascript">
    function makeReadOnly(){
        var textbox = document.getElementById("txtName");
        textbox.readOnly = "readonly";                          //readOnly is case-sensitive
        }

<body onload=" makeReadOnly ()">
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
    </div>
    </form>
</body>
The reason behind calling makeReadOnly function in body tag is to make textbox readonly when page is loading. You can also make textbox readonly after page load by just calling the makeReadOnly function on any textbox or button control.

That’s it!!…..Happy Programming...

No comments:

Post a Comment