How to set, change TextBox read only mode (ReadOnly)
TextBox ReadOnly property help us to generate a textbox which are on read only mode. you cannot change, edit, write, delete or
update text from read only textbox. this is a useful property when you want to make a textbox to disable editing for some user
and dynamically enable textbox for writing to other user. this example demonstrate us the use of textbox ReadOnly property.
here we uses a textbox and two button control. when you click a specified button then it change textbox for writable or read only mode.
it also show how can we change textbox ReadOnly property value programmatically.
TextBoxReadOnly.aspx
<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
TextBox1.ReadOnly = true;
}
protected void Button2_Click(object sender, System.EventArgs e)
{
TextBox1.ReadOnly = false;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>How to set, change TextBox read only mode (ReadOnly)</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:Green">TextBox Example: ReadOnly</h2>
<asp:Label
ID="Label1"
runat="server"
Text="Friend City"
>
</asp:Label>
<asp:TextBox
ID="TextBox1"
runat="server"
>
</asp:TextBox>
<br /><br />
<asp:Button
ID="Button1"
runat="server"
ForeColor="Crimson"
Text="Set ReadOnly Mode"
OnClick="Button1_Click"
Font-Bold="true"
/>
<asp:Button
ID="Button2"
runat="server"
Font-Bold="true"
ForeColor="Crimson"
Text="Clear ReadOnly Mode"
OnClick="Button2_Click"
/>
</div>
</form>
</body>
</html>



- How to set, change Label text programmatically
- How to set, change Label width programmatically
- How to use tool tip (ToolTip) in Label
- How to use theme and skin id (SkinID) in TextBox
- How to convert, change TextBox TextMode SingleLine to Password
- How to use theme and skin in TextBox
- How to show, hide, visible TextBox programmatically
- How to set, change TextBox width programmatically
- How to set, change TextBox font, text style