Archive for .Net

Understand DateTime, avoid Format-Hell

One of the most common mistakes programmers do is to treat the DateTime as string, or in another words always assuming a specific date format.

How DateTime Works
In strong typed languages like Java and .Net, DateTime contains the
date and time value as a consolidated numeric value without any format specification.
The culture aware ToString() method of DateTime converts the time value
according to the culture/format specifications of the system and configuration.

How to use?
Always use DateTime type for date and time values especially when savin/retriving DateTime values from/to Database.
Always use command parameters with proper types for passing values from application to database.

What to avoid?
Using string to contain DateTime values can become a disaster especially in large application.
You may find yourself trapped in a Format-Hell if you are assuming any particular format in calculation or representation
Never pass Datetime values as string across platforms or contexts for instance application-to-database

Leave a Comment

ASP.Net Page loading twice

If you are observing load event twice in a post back in ASP.Net page, check the following:

  • If Page_Load handler defined in Codebehind then AutoEventWireup property should be “false”
  • Check if you have mistakenly multiple event handlers registered for an event
  • Src or ImageURL attribute of your image control are defined and not empty (you can put %20 for blank)
  • bgColor or background is empty

Last two problems usually appears in one browser while disappears in other.

Comments (3)