You must Sign In to post a response.
  • Category: ASP.NET

    Make the controls read only


    How to make all the controls read only in the page.

    I have the request to make all the controls in an asp 2.0 read only, without the code change.

    How can i achieve this in UI or any scripts.

  • #762583

    If you dont want others to change the values of controls in UI then simply make the readonly property of control to true.

    <html xmlns="" >
    <title>Read only</title>
    <form runat="server" id="Form1">
    <asp:textbox ID="Textbox1" runat="server" ReadOnly="true" ></asp:textbox>
    <asp:textbox ID="Textbox2" runat="server" ReadOnly="true"></asp:textbox>
    <asp:Button ID="Button1" runat="server" Text="Button" Enabled="false" />


    Sai Krishna Reddy.

  • #762584
    Can you elaborate what do you mean by "without the code change." ?

    Do you want to make all control readonly on any action or by default you want those controls to be read only.

    Above answer is correct if you want controls to be readonly by default when page loads


    Happy Coding

    "Please don't forget to Rate this answer if you found it usefull"

  • #762586

    If you make all controls readonly, then what is the use?
    Do the control values are already set. If so then you can change the property of control in design or in script. make readonly="true".

    Like for textbox <asp:textbox ID="txtName" runat="server"
    ReadOnly="true" ></asp:textbox>

    By above setting you can just see the value of textbox which is already set, you can't modify as its readonly.

    Sridhar Thota.
    Editor: DNS Forum.

  • #762587
    Hello Dinesh,

    Should i know why you want to make ReadOnly to your all controls. If you are keeping ReadOnly to your controls than there will be no use of controls. It's just like they will become label. You can just see the value, can not change.

    You can do it by setting the property ReadOnly = true

    e.g :
    <asp:TextBox ID="ReadOnlyTextBox" runat="server" ReadOnly="True"></asp:TextBox>

    Hope this will help you.

    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #762590

    You can do like below to keep the controls readonly.

    Protected void Page_Load(object sender, EventArgs e)
    ControlsReadonly (Page.Controls);

    public void ControlsReadonly(ControlCollection ctrls)
    foreach (Control ctrl in ctrls)
    if (ctrl is TextBox)
    ((TextBox)ctrl).ReadOnly = true;
    else if (ctrl is DropDownList)
    ((DropDownList)ctrl). ReadOnly = true;
    else if (ctrl is Label)
    ((Label)ctrl). ReadOnly = true;
    ControlsReadonly (ctrl.Controls);

    hope this will helpful to you...

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

Sign In to post your comments