Support us MVC ASP.NET C# SQL Server WCF Written Test HR Round Subscribe C# Videos C# Programs Buy DVD

Best pactices in developing asp.net applications - Part 2


1. Do not catch general exception types - You should not catch Exception or SystemException. Catching generic exception types can hide run-time problems from the library user, and can complicate debugging. You should catch only those exceptions that you can handle gracefully.

2. Use properties instead of visible instance fields.

3. Follow the same naming conventions accross the solution.


4. Remove unwanted commented code, Indent code properly.

5. Use curly braces with in an if statement, even if there is a single statement in the if block. This will provide better readability.

6. Make sure to refactor your code to move the duplicated code to common reusable functions.

7. Move one time control settings into the .aspx page rather than having them in the code behind in if(!IsPostback) block.

8. Use inheritance whereever possible, which enables code reuse and also reduces the amount of code we have to write and test.

9. Move the reusable javascript functions to an external .js file instead of having them on the page.

10. For controls that are declarativley specified on the page, tie the event handlers to the controls events on the aspx page rather than initializing them in the codebehind. If the controls are built dynamically then we donot have a choice.

11. Make sure to check for nulls when using any type retrieved from a session, querystring or a database to avoid NullReferenceExceptions.

12. Use foreach loop instead of using for loop which may lead to out of boundary run time exceptions.

2 comments:

  1. With ForEach there is some performace cost so it should be use when required.

    ReplyDelete
  2. I m unable to understand ..

    Move one time control settings into the .aspx page rather than having them in the code behind in if(!IsPostback) block.

    please explain it with an example

    ReplyDelete

If you are aware of any other asp.net questions asked in an interview, please post them below. If you find anything missing or wrong, please feel free to correct by submitting the form below.

 
Disclaimer - Terms of use - Contact Us