JG Vimalan's Blog

It is all about coding!

Enable / Disable ASP.NET TextBox control using jquery

The following code snippet will give you an idea for enabling or disabling an asp.net control using jquery,

Here, based on the option (true or false), I am enabling / disabling a textbox, setting its background color to lightgrey and clearing the text.

<head runat=”server”>
<script src=”Scripts/jquery-1.8.2.min.js” type=”text/javascript”></script>
<script type=”text/javascript” language=”javascript”>
$(document).ready(function () {
var optionChkBox = $(“#chkOption”)
optionChkBox.change(function () {
var status = optionChkBox.is(‘:checked’)

var nameTxtBox = $(“#txtBoxName”)
if (status) {
nameTxtBox.attr(‘disabled’, false)
nameTxtBox.css(“background-color”, “white”)
}
else {
nameTxtBox.val(”)
nameTxtBox.attr(‘disabled’, true)
nameTxtBox.css(“background-color”, “lightgray”)
}
})
});
</script>

Advertisements

October 16, 2012 - Posted by | ASP.NET, JQuery, VS 2010

No comments 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: