Click here to Skip to main content
14,333,158 members

HijriDateView ASP.NET Control

Rate this:
4.91 (12 votes)
Please Sign up or sign in to vote.
4.91 (12 votes)
17 Mar 2009CPOL
An ASP.NET control that allows drawing current Hijri date in string format on an ASP.NET page.


Some time ago, working on a project, I faced with the necessity of showing date in Hijri format (Islamic calendar) on an ASP.NET page. Although the FCL contains a HijriCalendar class, it corresponds to an algorithm of calculation only and doesn't allow formatting output for showing date in string format. Therefore, the HijriDateView control, described in this short article, was developed.

How it looks

HijriDateView is an ASP.NET composite control that consists of a Panel (corresponds to an HTML Div) and a plain text inside this Panel. By default, on a page, it looks like:

Image 1

Since the Panel class is used as a container, any visual style can be applied to the control, to show it like this:

Image 2

or this:

Image 3

or this:

Image 4

How to use the control

Image 5

Just compile the attached project, or use the already compiled assembly from the file. Reference IslamicTools.dll from your ASP.NET WebForms project and a new item will appear on your Visual Studio's toolbox. Just drag it to the appropriate place on your ASP.NET page, and code similar to this will be generated:
<IslamicTools:HijriDateView ID="hijriDateView" runat="server">

Now, you can set some properties of the control:

  • Language - The language that will be used for transliteration of the Arabic month names. Currently, the possible values are English and Russian.
  • IncludeArabic - Indicates whether to show Arabic text in the resulting inscription or not.
  • Date - Date used for conversion and showing. If it is not specified, the current date will be used (DateTime.Now).

All regular ASP.NET control visual properties can also be set here. Now, just compile and run your page to see the result.

How it works

There are the four files related to the control.

Image 6

  • HijriDate.cs - contains the HijriDate class that envelops the HijriCalendar class from the FCL.
  • HijriDate.xml - contains different transliterations of months including Arabic.
  • HijriDateView.bmp - bitmap for the toolbar.
  • HijriDateView.cs - contains the HijriDateView Web Control that is used on an ASP.NET page.

During the lifecycle of the ASP.NET page, a new instance of the HijriDateView control is created. We set the default values for the Date, Language, and IncludeArabic properties in the constructor. They will be overridden if the user sets their values manually. On the LoadComplete stage of the page's lifecycle, the CreateChildControls method of HijriDateView will be called. It will prepare a container (Panel) and a place for the text (LiteralControl), and at the same time, a new instance of the HijriDate class will be created and used with the defined properties:

protected override void CreateChildControls()
  Panel pnl = new Panel();
  HijriDate hd = new HijriDate(dt);
  string label = String.Format("<nobr>{0}</nobr>", 
                               hd.ToString(language, includeArabic));
  LiteralControl lc = new LiteralControl(label);

The HijriDate class takes a DateTime object as an input. A new instance of HijriCalendar for a specified date is created in the constructor as well as private numeric fields that correspond to year, number of month, and number of days in a month, and are filled out. Also, string recourses are loaded from the HijriDate.xml file.

public HijriDate()
   : this(DateTime.Now)
public HijriDate(DateTime dt)
  hijriCalendar = new HijriCalendar();
  hijriYearNumber = hijriCalendar.GetYear(dt);
  hijriMonthNumber = hijriCalendar.GetMonth(dt);
  hijriDayNumber = hijriCalendar.GetDayOfMonth(dt);

HijriDate.xml has the following format:

<?xml version="1.0" encoding="utf-8" ?>
  <month number="1">
  <month number="2">
  <month number="12">
    <English>Dhu al-Hijja</English>
    <Arabic>ذو الحجة</Arabic>

The HijriDate class has an overridden method ToString() that does all the work for converting the numeric representation of a date into a string:

public override string ToString()
  return ToString(SupportedLanguages.English, true);

public string ToString(SupportedLanguages language, 
                       bool includeArabicInscription)
  return String.Format("{0} {1} {2}", hijriDayNumber.ToString(), 
  GetMonthName(language, includeArabicInscription),

That’s it. As you might have noticed, not all code is provided here, particularly the methods LoadHijriDateXml() and GetMonthName() are not even described. But their behavior should be obvious from their names, and their code is available in the file.


A working control can be seen at The IslamicTools library contains only a HijriDateView control for now. It is about to be extended with other controls. If you have any ideas or suggestions, you are kindly welcome to contact me.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Bashir Magomedov
Software Developer (Senior)
United Kingdom United Kingdom
Work: HSBC (
Regalia: PhD in CS, MCAD, MCPD: Web Developer, MCTS: .Net Framework 2.0., 3.5.
Interests: Programming, artificial intelligence, C#, .NET, HTML5, ASP.NET, SQL, LINQ.
Marital Status: Married, daughter

Comments and Discussions

Generalgreat job thanks Pin
Mohamed Abdullah 8222-Mar-09 23:39
memberMohamed Abdullah 8222-Mar-09 23:39 
GeneralRe: great job thanks Pin
Bashir Magomedov23-Mar-09 1:31
memberBashir Magomedov23-Mar-09 1:31 
GeneralExcellent Pin
Muneeb R. Baig20-Mar-09 1:35
memberMuneeb R. Baig20-Mar-09 1:35 
GeneralRe: Excellent Pin
Bashir Magomedov20-Mar-09 7:23
memberBashir Magomedov20-Mar-09 7:23 
GeneralRe: Excellent Pin
Muneeb R. Baig20-Mar-09 10:20
memberMuneeb R. Baig20-Mar-09 10:20 
GeneralRe: Excellent Pin
Bashir Magomedov20-Mar-09 10:23
memberBashir Magomedov20-Mar-09 10:23 
GeneralHijriDateView ASP.NET Control Pin
samerh17-Mar-09 19:55
membersamerh17-Mar-09 19:55 
GeneralRe: HijriDateView ASP.NET Control Pin
Bashir Magomedov17-Mar-09 20:05
memberBashir Magomedov17-Mar-09 20:05 
GeneralRe: HijriDateView ASP.NET Control Pin
samerh17-Mar-09 20:27
membersamerh17-Mar-09 20:27 
GeneralRe: HijriDateView ASP.NET Control Pin
Bashir Magomedov18-Mar-09 6:07
memberBashir Magomedov18-Mar-09 6:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Posted 17 Mar 2009


23 bookmarked