Lions Den

The Code and Times of Hanan Schwartzberg

About Hanan | Hanan's CV | Contact Hanan

September 10, 2009

CalendarExtender Plus 1.0.2.0

Click Here to download the latest version of CalendarExtender Plus and documentation.

The CalendarExtender Plus is a modification of the calendar extender that ships as part of the Ajax Control Toolkit. There are two main features added to the control. First, you can limit the selectable dates to a specified date range. Second, there is now the option to show an alternate header. The new header includes two DropDown Lists, one to select the month and one to select the year.

(more…)

June 16, 2009

Introducing CalendarExtender Plus

Maximum Date - May 15th, 2009
Click Here to download the latest version of CalendarExtender Plus and documentation.

The CalendarExtender Plus is a modification of the calendar extender that ships as part of the Ajax Control Toolkit. There are two main features added to the control. First, you can limit the selectable dates to a specified date range. Second, there is now the option to show an alternate header. The new header includes two DropDown Lists, one to select the month and one to select the year.

The available dates can be limited using the MaxDate and MinDate properties.

<cc1:CalendarExtenderPlus runat="server" ID="cepExample" 
    TargetControlID="txtExample" 
    MaximumDate="01/01/2009" MinimumDate="5/15/2009 />

Setting the ShowDdlHeader to true will show the heading with dropDownLists to select the month and year.

<cc1:CalendarExtenderPlus runat="server" ID="cepHeaderExample" 
    TargetControlID="txtExample" ShowDdlHeader="true" />

DropDownList

The Calendar Extender Plus has a few other enhancements, including the ability to show or hide the arrows in the heading to move back and forth a month, and a property to show or hide today’s date at the bottom of the calendar.

Since the CalendarExtender Plus is a modification of the standard extender it has all the properties and functionality of the original. It can be skinned using the normal css, and automatically fills the textBox with no need for additional javascript.

The CalendarExtender Plus is free to download, use, and distribute with your project. Any feedback is greatly appreciated!

June 7, 2009

ComboBox ClientSide onChange Event

Filed under: Ajax Control Toolkit,ASP.NET,C#,Client Side — Tags: , , , , , , — Hanan Schwartzberg @ 4:57 pm

The Issue

The comboBox has a couple of server side events to deal with field changing.

  • OnSelectedIndexChanged
  • OnTextChanged

How can we catch the comboBox changing on the client side?

The Solution

Without access to these function on the client side, we need to use the client side events of the textBox that is contained within the comboBox. As with any textBox this one also has the onChange event, but the event does not run when the text was changed and the focus moved to another field. There are a few options:

  • onKeyPress
  • onKeyUp
  • onBlur

The problem with onKeyPress is when it gets to the javascript function the value of the textBox is has not changed yet, leaving onKeyUp and onBlur. While onKeyUp will give the desired effect when the user presses a key on the keyboard, part of the point of a comboBox is the ability to use the mouse, which will not be captured by this event, leaving onBlur as the remaining option. It’s still not perfect, since the event won’t run until the focus is moved off the comboBox, but it appears to be the best option. In some cases you may want to use both onKeyUp and onBlur to get the best of both events, but be careful because when the user uses the keyboard and the moves the focus your event will run twice.

In the example below I have a comboBox named cmbExample and a javascript function that accepts the textBox calling it as a parameter, cmbExample_OnBlur(textBox). I add the onBlur event to the textBox in the Page_Load method in the code behind.

protected void Page_Load(object sender, EventArgs e)
{
    TextBox textBox = cmbExample.FindControl("TextBox") as TextBox;
 
    if (textBox != null)
    {
        textBox.Attributes.Add("onBlur", "cmbExample_OnBlur(this);");
    }
}

June 3, 2009

AjaxControlToolkit ComboBox “Invalid argument.”

Filed under: Ajax Control Toolkit,ASP.NET,Client Side — Tags: , , , , , — Hanan Schwartzberg @ 12:03 pm

The Control

Microsoft recently released version 3.0.30512 of the AjaxControlTookit, available here. One of the new controls is the ComboBox, which “provides a DropDownList of items, combined with TextBox.”

The Issue

Placing the ComboBox in a container that has the style attribute “display: none;” throws the error “Invalid argument.” This is true if the container is a panel with the attribute set explicitly, or a different container such as a TabPanel that implicitly has the display attribute set to none when it is not shown.

(more…)

May 14, 2009

Maintaining Dynamically Added Controls

Filed under: ASP.NET,C# — Tags: , , , , , , — Hanan Schwartzberg @ 5:45 am

Two Questions

  1. How can I keep a dynamically added control from disappearing on postBack?
  2. When in the life cycle of the page should I do this?
Click Here to download this solution

(more…)

March 16, 2009

Conditional Where in LINQ

Filed under: C#,LINQ — Tags: , , , — Hanan Schwartzberg @ 11:38 pm

Recently I needed to build a LINQ query with a conditional where clause. After a bit of searching I found a few solutions. In essence they all seem to come down to two methods. The first method is to run a second LINQ query to filter the results from the first one. The second method is to run a totally separate LINQ query for each scenario. In deciding which to use I wrote a test program that pit these two methods against each other and found that the latter was noticeably more efficient (when running the query 5000 times).

(more…)

February 22, 2009

A container user control that can be used with the ModalPopupExtender

Filed under: ASP.NET — Tags: , , , , — Hanan Schwartzberg @ 4:56 pm

I am currently working on a project that has a good number of modalPopups across several pages. Each one has an OK and a Cancel button and either some text or other controls. To make it easier to maintain all these popups, I set out to build a user control that could act as a panel. Then for each popup I could simply add the controls that are specific to that popup. This turned out to be more difficult than I had anticipated. After some time and searching I came up with the following solution. (more…)

January 28, 2009

ModalPopup Flicker When Exiting the Page

Issue

When the user causes a complete postback all of the panels associated with ModalPopupExtenders flicker and become visible for a moment before the page disappears as the browser loads the next page. NOTE: This is occurring while exiting the page, not when the page loads and could not be replicated on other pages.

What did not work

A quick Google search yielded this post relating to the flicker occassionaly seen when the page loads:  http://mattberseth.com/blog/2007/08/how_to_stop_the_modalpopup_fli.html

To get around this, I explicitly set the display style to ‘none’ on the popup Panel.  This has solved the problem.

I tried this two ways (not at the same time):

  • I added display:none; to my css class that each panel uses.
  • I added style=”display:none;” the to the panel’s tag (more…)
Home | Site Design | Banner Design | Code Den | Offsite Posts | Downloads | Photography | About Hanan | Hanan's CV | Contact Hanan
Copyright © 2009 Hanan Schwartzberg. All rights reserved.