Checking if any control in view has changed in ASP.NET

The typical way to check for whether anything has changed in the view when you’re navigating away from a page is to bind a method to the change event of each input and to set a flag if this has happened. This flag is then checked when leaving the page and a notification is shown to the user if the flag is raised. This is all good but it does not take into account things like changing the order of inputs and changing values back to their original values. Also, creating dynamic elements makes this way of doing things a bit tricky because you have to add registering of the handlers to each method which adds new elements.

Just recently I had to implement this kind of checkin Continue reading

Tranasction and TRY – CATCH in SQL SERVER


      BEGIN TRANSACTION  — BEGIN TRANSACTION should come before or after BEGIN TRY that is not equally important, but it feels more right to have it inside the TRY-CATCH section.


  COMMIT  —   Don’t write this COMMIT  after end of CATCH block because  if you get an error and wind up in the CATCH up section, you will roll back the transaction. When you exit the CATCH block, you will
attempt to commit, but there is nothing to commit, so there will be a new error.




THROW  — THROWING the original exception to the application. THROW  statement is available in SQL server 2012. RAISEERROR() vs THROW:

END CATCH Continue reading

Static Readonly variables

Why Static variables?

static variable shared the value of it among all instances of the class. Changes done to static variable are visible across methods. Static variable, that means it exists exactly one place in memory for the duration of the program. Static class variables are like globals. Static variables belong to type, not to its instance. You can change the value of a static variable in any of the method of that class.   Continue reading

Setting Return statement to Null in the finally block.

For example, If x is a local variable, will be effectively set to null anyway when the method is exited and the value of the return value is not null.

The finally statement is executed, but the return value isn’t affected. The execution order is:

  1. Code before return statement is executed
  2. Expression in return statement is evaluated
  3. finally block is executed
  4. Result evaluated in step 2 is returned

Continue reading