By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,016 Members | 1,038 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,016 IT Pros & Developers. It's quick & easy.

Simple question on Calendar control

P: n/a
Dear all,

I have a webform with a calendar control on it. When loaded the calendar is
set to the current date. Depending on a criteria from a database field,
calendar day cell appears with red background color for the selected month.
This is done by using the Calendar_DayRender event. This works fine

What I need to do next is that if my user click on either the NextMonth or
PrevMonth, I should get the same behaviour for day cells background. In the
sense that if there is a day from the database from that new selected month
that havve this particular criteria, the background color of the cell smust
also be in red color.

Problem I have is that DayRender event is not trig anymore as long as
control is loaded. Then I have try to use the VisibleMonthChanged event but
how can get then scan day cells in order to change the style ?

thnaks for your help
regards
serge
Nov 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
serge calderara wrote:
Dear all,

I have a webform with a calendar control on it. When loaded the calendar is
set to the current date. Depending on a criteria from a database field,
calendar day cell appears with red background color for the selected month.
This is done by using the Calendar_DayRender event. This works fine

What I need to do next is that if my user click on either the NextMonth or
PrevMonth, I should get the same behaviour for day cells background. In the
sense that if there is a day from the database from that new selected month
that havve this particular criteria, the background color of the cell smust
also be in red color.

Problem I have is that DayRender event is not trig anymore as long as
control is loaded. Then I have try to use the VisibleMonthChanged event but
how can get then scan day cells in order to change the style ?

thnaks for your help
regards
serge


Hmmmm, works for me. DayRender triggers on postback (from change of
month). Make sure you're not forgetting to hook up the event handler on
every postback. Here's a simple (read: dumb) example I tried, just
create a new form and drop a Label and Calendar on it...here's the
code-behind code:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace ctestweb
{
/// <summary>
/// Summary description for Calendar.
/// </summary>
public class Calendar : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Calendar Calendar1;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);

Calendar1.DayRender += new DayRenderEventHandler(Calendar1_DayRender);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
if (e.Day.DayNumberText == "16")
{
Label1.Text = "I see the 16th day of the " + e.Day.Date.Month + "
month.";
}
}
}
}

--
craig
Microsoft MVP - ASP/ASP.NET
Nov 23 '05 #2

P: n/a
thnak you it works

"Craig Deelsnyder" wrote:
serge calderara wrote:
Dear all,

I have a webform with a calendar control on it. When loaded the calendar is
set to the current date. Depending on a criteria from a database field,
calendar day cell appears with red background color for the selected month.
This is done by using the Calendar_DayRender event. This works fine

What I need to do next is that if my user click on either the NextMonth or
PrevMonth, I should get the same behaviour for day cells background. In the
sense that if there is a day from the database from that new selected month
that havve this particular criteria, the background color of the cell smust
also be in red color.

Problem I have is that DayRender event is not trig anymore as long as
control is loaded. Then I have try to use the VisibleMonthChanged event but
how can get then scan day cells in order to change the style ?

thnaks for your help
regards
serge


Hmmmm, works for me. DayRender triggers on postback (from change of
month). Make sure you're not forgetting to hook up the event handler on
every postback. Here's a simple (read: dumb) example I tried, just
create a new form and drop a Label and Calendar on it...here's the
code-behind code:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace ctestweb
{
/// <summary>
/// Summary description for Calendar.
/// </summary>
public class Calendar : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Calendar Calendar1;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);

Calendar1.DayRender += new DayRenderEventHandler(Calendar1_DayRender);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
if (e.Day.DayNumberText == "16")
{
Label1.Text = "I see the 16th day of the " + e.Day.Date.Month + "
month.";
}
}
}
}

--
craig
Microsoft MVP - ASP/ASP.NET

Nov 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.