2013-01-15

Importance of custom error pages

Instead of providing a cryptic error to the users, you can display your own custom error page when an error occurs. It's not nice to display a cryptic error message to the user (Yellow screen) which requires technical knowledge to understand. The user really don't care about what's gone wrong technically. What (s)he cares is an understandable error message and/or how to report it to the website owners and/or how to recover from the error.

To know the actual error for the developers, you can use a logging mechanism. It’s not nice to show the Yellow Screen of Death (YSoD) to the user. Hide it. Log your errors. You (Developer) are the only person who is worrying about the actual error message and what went wrong. From the user’s perspective, it’s not important. So always remember to use a custom error page. You can achieve this with asp.net Custom error pages.

2013-01-11

Sri Lanka .NET forum monthly user group meeting – January 2013

We hosted the first new year .NET forum user group meeting on 10th of January 2013 at Microsoft Sri Lanka. Thank you all the people who have attend! Following are the details of the session I’ve delivered

Topic – Logging with ASP.NET (Introduction to log4net)

Session duration - 45 minutes

Date – 10th January 2013

You can get the presentation slides from the below link

https://skydrive.live.com/redir?resid=56E5E527D356065A!117&authkey=!AGNPUGTyD82yJbc

You can download the sample application I’ve used from the following link

https://skydrive.live.com/redir?resid=56E5E527D356065A!110

Following are some of the photos taken at the session.

1001201325710012013258

10012013261

2013-01-04

Got awarded as a Microsoft Most Valuable Professional (MVP)

After celebrating the new year at my office, I went home as usual. Around 8:30PM, I saw there were tweets appearing in my tweet feed saying “Congratulations renewed MVPs and welcome new MVPs”, “Congratulations 2013 MVPs” etc. I checked the time of those tweets and I saw those were about 45 minutes-30 minutes ago. There were no new mail notification in my e-mail account. But with a slight hope, I opened it and saw spam(1). I clicked on it and saw the most awaited e-mail. There it was in my spam folder!

I got the e-mail from MVP award saying I’ve been awarded as a 2013 Microsoft Most Valuable Professional for my contributions in ASP.NET/IIS technical communities.

I started my developer life with C and Visual Basic. As I step in to my university, I learned Java, PHP and C++. I was mastered in Java (J2SE and J2ME). But when I started my industry placement (training period) at IronOne technologies, I was required to do a Windows mobile project along with an ASP.NET project. That’s how I started to develop web application with ASP.NET Smile

I did iPhone and Android projects before I fully step in to web applications development with ASP.NET. During the past four years, Visual Studio, ASP.NET, IIS, HTML, JavaScript/jQuery, CSS became a part of my day to day life. I did projects using those technologies and provided answers on the international ASP.NET and IIS forums. By providing answers during 2011/2012, I became the 3rd Top Answerer in ASP.NET forums and 16th Top Answerer in IIS forums.

TopAnswerers

Currently I’m holding the 45th position of their Hall of Fame among 176350 members.

TopAnswerersIIS

Apart from Contributing to the forums, I also contributed to the technical community by posting sample codes and other relevant articles here.

Also, I’m an active member of Sri Lanka .NET forum and actively share my knowledge through Developer Help Facebook group, Sri Lanka .NET Forum Facebook group and via Twitter.

Sometimes, I contribute to the ASP.NET Wiki section too.

I have MANY people to thanks for this award. My parents, my loving sister, my brother in law, my friends, Moderators, Microsoft Forum Technicians and my peer members at both ASP.NET and IIS forums, Staff at Microsoft Sri Lanka, Staff at Singapore Microsoft,  MVPs in Sri Lanka, IronOne staff and there are many more to list here. Thank you all who have helped me!

Finally, Thank you very much Microsoft for appreciating my efforts to share my knowledge among the community.

Cheers! Smile

2013-01-01

How to publish empty folders with Visual Studio publish

When you use the Publish option in Visual Studio, it will not publish the empty folders. But sometimes we need the empty folders too to be published (In case if we wish to keep some data in those folders after we publish the site). If we are going to create those folders at the production environment manually, it would be a pain since we have to create those each time we publish the application and we have to take care about the spellings of the folder names if we have used them in the code. There is a little trick we can do to make empty folders get published.

1. Add an empty text file inside that folder.

2. Go to the properties of the text file and set the Build Action to Content.

Untitled

Now it will publish the empty folder too.

How to disable dates and prevent from selecting in asp:Calendar controller

My first post in new year. Happy new year everyone!! Smile

Sometimes we need to prevent users from selecting future dates or past dates or some date range. The following example shows how to achieve it in asp:Calendar control.

ASPX code

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Tests.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:Calendar ID="Calendar1" runat="server" ondayrender="Calendar1_DayRender"></asp:Calendar>
    </div>
    </form>
</body>
</html>

Code behind (C#)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Tests
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
        {
            if (e.Day.Date.CompareTo(DateTime.Today.AddDays(5)) >0)
            {
                e.Day.IsSelectable = false;
                e.Cell.ForeColor = System.Drawing.Color.Gray;
            }
        }
    }
}

In the code behind I’m checking the dates in the calendar on the DayRender event and if the date is more than 5 days after the today’s date, I’m disabling those date in the calendar. I’m adding 5 days to the today’s date (Which means it will get the date of 5 days after the today). Then I’m comparing it with the dates in the calendar control. If the calendar dates are greater than that value (Which means those are future dates than the date from 5 days from today), I’m setting the IsSelectable property to false for those days and setting the ForeColor to Gray. So those days will be disabled on the calendar control.

In short, this calendar control will not let users to select the dates more than 5 days from the today’s date.