戰地連結︰ Home My Flickr NBA.com About

2009年2月14日星期六

Cannot view the contents of a (.chm) file

Overview

I just get an e-book and find that all of the pages are dead. With some searching I find that the file is blocked by windows.

The solution is to unlock the .chm file. To do this:

  1. Right-click on the .chm file, select "Properties"
  2. Click "unlock"
  3. Done!

Reference

解决打开CHM格式文件出现“网页不能浏览”错误的方法

You cannot open HTML Help files....

2009年2月5日星期四

Add a select / deselect all checkbox to an ASP.NET checkbox list control

Overview

The code below demonstrate how to use JavaScript to get all the checkbox elements of a particular checkbox list, and then check / unchecked them base on the status of another checkbox (the sender).

This technique is also useful when you want to do other operation (e.g. ensure single selection) to all checkboxes of a checkbox list.

Reference

Check/Uncheck all items in a CheckBoxList using ASP.NET and Javascript

Code Snippet

This code is directly copied from Check/Uncheck all items in a CheckBoxList using ASP.NET and Javascript

function CheckBoxListSelect(cbControl, state)

{  

    var chkBoxList = document.getElementById(cbControl);

    var chkBoxCount= chkBoxList.getElementsByTagName("input");

    for(var i=0;i<chkBoxCount.length;i++)

    {

        chkBoxCount[i].checked = state;

    }

 

    return false;

}

2009年2月3日星期二

Multi-line Text boxes (Text area) behave incorrectly with Default Button in Firefox

Overview

I open form with a default button and a Multi-line ASP.NET text box (text area) in Firefox 3. When I hit "Enter" key in the text area, I expect the text area to start a new line. However, the default button is triggered.

Reference

Multiline Textboxes and DefaultButton in Firefox

2009年1月21日星期三

Restrict date range in Calendar

Overview

By default, Calendar control won't allow you to restrict the selectable date range. However, we can achieve this by doing two things:

  1. Restrict user from navigating to a month outside the range
  2. Restrict user from selecting a day outside the range

Reference

Visual Studio .NET - restrict date range in Calendar - eggheadcafe

Disable calendar day select link - eggheadcafe

Steps

Restrict user from navigating to a month outside the range

To achieve this, we can set the "NextMonthText" and "PrevMonthText" fields of the Calendar control to hide the link navigating to next or previous month.

Code Snippet:

protected void Cal_PreRender(object sender, EventArgs e)

        {

 

            if (Cal.VisibleDate.Year > 2009 || (Cal.VisibleDate.Year == 2009 && Cal.VisibleDate.Month >= 12))

            {

                Cal.NextMonthText = string.Empty;

            }

            else

            {

                Cal.NextMonthText = ">";

            }

 

            if (Cal.VisibleDate.Year < 2000 || (Cal.VisibleDate.Year == 2000 && Cal.VisibleDate.Month <= 1))

            {

                Cal.PrevMonthText = string.Empty;

            }

            else

            {

                Cal.PrevMonthText = "<";

            }

        }

Restrict user from selecting a day outside the range

This can be achieved by controlling the "IsSelectable" field in the "onDayRender" event handler of the Calendar.

Code Snippet:

protected void Cal_DayRender(object sender, DayRenderEventArgs e)

        {

            if (e.Day.Date.Year == 2009)

            {

                e.Day.IsSelectable = false;

            }

        }

ListView Control vs Repeater Control

Overview

Repeater control is one of my favorite ASP.NET controls because of its flexibility in UI design. However it lack some useful functions like "Sorting", "Paging" & "Data modification".

Now in ASP.NET 3.5 we have a ListView control which seems to do all of the Repeater's jobs and more. Below are some article talking about ListView control.

Reference

The asp:ListView control (Part 1) - Scott Guthrie

The ListView Dominates The Repeater - SingingEels

ListView Web Server Control Overview - MSDN