Enable TextBox, Disable TextBox and ReadOnly TextBox Control programmatically

Enable, Disable and ReadOnly TextBox Control programmatically

– Hi, Here we lean this asp.net tutorials, How to enable Textbox control, Disable TextBox control and Readonly Textbox control in ASP.Net C#.

– First we have to Design the ASP.Net Page with One TextBox along with Theree(3) Button Server Control. The ASP.Net Enable, Disable, Readonly TextBox control Design Code is below :

– write below code in head body tag:-

<table style=”width: 352px”>
<tr>
<td style=”width: 100px; text-align: right”> Enter Value :
</td>
<td colspan=”2″ style=”text-align: left”>
<asp:TextBox ID=”TextBox1″ runat=”server”>
</asp:TextBox></td> </tr> <tr>
<td style=”width: 100px; height: 26px”>
</td> <td colspan=”2″ style=”height: 26px; text-align: left”>
&nbsp;<asp:Button ID=”Button1″ runat=”server” OnClick=”Button1_Click” Text=”Enable” />
<asp:Button ID=”Button2″ runat=”server” OnClick=”Button2_Click” Text=”Disable” />
&nbsp;<asp:Button ID=”Button3″ runat=”server” Text=”ReadOnly” />
</td>
</tr>
</table>

Write below code for Enable TextBox:-

protected void Button1_Click(object sender, EventArgs e)
{
TextBox1.Enabled = true;
}

TextBox control Enable in ASP.Net
TextBox control Enable in ASP.Net

write below code for Disable TextBox:-

protected void Button2_Click(object sender, EventArgs e)
{
TextBox1.Enabled = false;
}

TextBox control Enable in ASP.Net
TextBox control Enable in ASP.Net

Write below code for ReadOnly TextBox:-

void Button3_Click(object sender, EventArgs e)
{
TextBox1.ReadOnly = true;
}

ReadOnly TextBox in ASP.Net
ReadOnly TextBox in ASP.Net

–  Here, we learnt problematically Enable, Disable, ReadOnlyTextbox control in ASP.Net TextBox Example.

– The same things we can do without Problematically like this:
Just SET the TextBox Property Enabled = True / False for Enable / Disable Textbox Control.

For ReadOnly SET TextBox Property ReadOnly = True / False for ReadOnly on/off Textbox.

– In above ASP.Net Tutorials, we have learn  How to enable Textbox control, Disable TextBox control and Readonly Textbox control in ASP.Net C#.

– I hope, will enjoy this  ASP.Net TextBox Example of  Enable, Disable, Readonly TextBox control of asp.net.

Leave a Reply

Your email address will not be published. Required fields are marked *