Home > ASP.Net, Jquery > Enable or Disable ASP.NET TextBox on Button Click Event Using JQuery

Enable or Disable ASP.NET TextBox on Button Click Event Using JQuery


Hi all,

try this example to Enable or Disable ASP.NET TextBox on Button Click Event Using JQuery

<html>
<head>
<title>Enable/Disable Asp.net Textbox</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js">
</script>
<script type="text/javascript">
$(document).ready(function () {
$("#btnDisable").click(function () {
$("input:text").attr("disabled", "disabled");
return false; //to prevent from postback
});
$("#btnEnable").click(function () {
$("input:text").removeAttr("disabled");
return false; //to prevent from postback
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<table>
<tr>
<td colspan="2">
<b>* Click on any button and try to type text in textbox for demo</b>
</td>
</tr>
<tr>
<td>
&nbsp;
</td>
</tr>
<tr>
<td>
Try to type:
</td>
<td>
<asp:TextBox ID="txtTestbox" runat="server" ClientIDMode="Static" />
</td>
</tr>
<tr>
<td>
&nbsp;
</td>
<td>
<asp:Button ID="btnDisable" runat="server" Text="Disable" />
<asp:Button ID="btnEnable" runat="server" Text="Enable" />
</td>
</tr>
</table>
</form>
</body>
</html>

Good Luck.

Advertisements
Categories: ASP.Net, Jquery
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: