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.attr(‘disabled’, true)
nameTxtBox.css(“background-color”, “lightgray”)

October 16, 2012 Posted by | ASP.NET, JQuery, VS 2010 | Leave a comment

Using files in C# unit testing

In order to use files during unit testing, the files must be added in the unit test project as shown below,

To demonstrate, I am using an xml file in my unit test.

The file should be available in the deployment folder for test methods to access. In order to achieve that, browse to Test -> Edit Test Settings -> Local.testsettings in Visual Studio menu. Test Settings window will be displayed as shown below,

Go to Deployment and Check ‘Enable Deployment’. Now add the file(s) (from test project folder) using the “Add File…” button.

In the unit test, specify the xml file name in the DeploymentItem attribute as shown below,

Now, when test is running, the file will be available in the deployment directory and it can be accessed using TestContext.DeploymentDirectory.

October 5, 2012 Posted by | C#.NET, VS 2010 | Leave a comment

This OdbcTransaction has completed; it is no longer usable.

I got this exception when I was trying to perform multiple row insert in a DB2 database using Enterprise Library 5.0 and DbTransaction.

Cause of this exception:

I was trying to invoke ExecuteNonQuery method from Database object instead of DbCommand object. And, when one of the SQL failed (due to syntax or data problem), the catch block caught the exception and tried to rollback but DbTransaction.Rollback failed and it was throwing the above exception.


In order to solve this issue, set the transaction object in DBCommand.Transaction property and ExecuteNonQuery in DbCommand. Plus, the connection should be in open state when trying to rollback. The working code sample is given below,

internal static bool InsertRecords(List<string> sqlCollection)
Database database = DatabaseFactory.CreateDatabase(Utility.GetDB2ConnectionName);

using (DbConnection dbConnection = database.CreateConnection())
DbCommand dbCommand = dbConnection.CreateCommand();
DbTransaction dbTransaction = null;

dbTransaction = dbConnection.BeginTransaction();
dbCommand.Transaction = dbTransaction;

foreach (string sql in sqlCollection)
dbCommand.CommandText = sql;
dbCommand.CommandType = CommandType.Text;

return true;
catch (Exception error)

if (dbTransaction != null)

return false;

October 2, 2012 Posted by | ASP.NET, C#.NET, DB2, Enterprise Library 5.0, VS 2010 | | Leave a comment