Simple question on Calendar control

G

Guest

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
 
C

Craig Deelsnyder

serge said:
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.";
}
}
}
}
 
G

Guest

thnak you it works

Craig Deelsnyder said:
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.";
}
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top