Tuesday 2 October 2007

Ajax Calendar Extender and Master Pages

I thought I might as well share this, if it's not common knowledge.

If you have a MasterPage.page and you want to include styles based on the child page you can add the script into the page but this will result in an issue with viewing the designer in Visual Studio 2005. I eventually found a solution to add the stylesheet to the header in code:


protected void Page_Load(object sender, EventArgs e)
{
HtmlLink cssLink = new HtmlLink();
cssLink.Href = "~/default.css";
cssLink.Attributes.Add("rel", "stylesheet");
cssLink.Attributes.Add("type", "text/css");
Header.Controls.Add(cssLink);

}

On the calendar extender I was puzzled to see that when a user selected the date the control remained visible. To get round this use an image and the PopUpControlID of the extender and the control will disappear. By setting the text boxes to Enabled=false the user only has the option of using the image to get the calendar to show. I suppose you could use the TextChanged event but this would not stop user error.

No comments: