473,320 Members | 1,820 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Simple question on Calendar control

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
2 1878
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Tim Graichen | last post by:
Hello, I am making use of the Active X calendar control (mscal.Calendar.7) in several places in my main form, with the following code Below is an example of the code I'm using for the...
5
by: Miguel Dias Moura | last post by:
Hello, i am trying to create a .css file with several styles and apply them to the calendar control so i can change the look of: 1. Text Type and Format (Bold, Underline, etc) 2. Background...
1
by: bill yeager | last post by:
I would like to place the currently selected date (retrieved from the database) on a calendar control which is embedded inside a datagrid. However, I can't find the ID of the control to do so....
0
by: maxrawson | last post by:
First, let me start by saying my asp.net experience is still in it's infancy so please bare with me as I try to explain my situation. I have created a single page that with the use of many...
2
by: Caesar Augustus | last post by:
First, let me start by saying my asp.net experience is still in it's infancy so please bare with me as I try to explain my situation. I have created a single page that with the use of many...
3
by: Peter | last post by:
Is there anyway to make the System.Web.UI.WebControls.Calendar to display only Month Name and Year, like: January, 2006 February, 2006 ..... .... .... ....
3
by: =?Utf-8?B?UGFycm90?= | last post by:
I applied the following Ajax code in my web page which has a calendar control to keep my page from completely reloading everytime something was changed. <atlas:ScriptManager ID="ScriptManager1"...
7
by: John Kotuby | last post by:
Hi all, I am trying to use a calendar server control which I have ID="Calendar1" in the source code. What I am trying to do is emulate a JavaScript calendar that was being used in an older ASP...
3
by: thorpk | last post by:
I posted this problem earlier in the month and some one decided it was better to change the subject and ask a completely different question. I am therefore reposting. I am hoping some one can...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.