473,494 Members | 2,027 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

problem in rendering the calendar control

Hi All,

I want to create custom control by using Web.UI.WebControls.Calendar,
in which I want to set few days with different color. I had created two
property to set the color and storing in viewstate. I had created 4
methods to Add/Remove my special dates in viewstate.

Up to here all seems perfect, but how do I used it in prerender event
for my new calendar control.

Scenario:
I want to creae a web applicaiton which for Even Organizer.
I want to create my own custom calendar control/ User control which
show the dates in different color. There are list of dates on which the
event is organized, and there are few dates which are expiered. I want
to display this dates in two different color. I can easily implement it
in OnDayRender(object sender, DayRenderEventArgs e) event of system
calendar control. But i want to use same functionality on multiple web
pages, and for that i want to create Custom Control/User Control.

My quesion is where should i put my code to change the color of dates.

Below is my stuff. Your ideas also most welcomed.
Thanks & Regards,
Rushikesh

/////////////*********** CODE FOR EventCalendarControl
******************////////////////

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Collections;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
namespace MACT.Controls
{
[ToolboxData("<{0}:EventCalendarControl
runat=server></{0}:EventCalendarControl>")]
public class EventCalendarControl :
System.Web.UI.WebControls.Calendar
{
[Bindable(true),
Category("Appearance"),
DefaultValue("")]

#region Properties
public Color EventColor
{
get
{
object o = ViewState["EventColor"];
if (o == null)
return Color.Empty;
else
return (Color)o;
}

set
{
ViewState["EventColor"] = value;
}
}

public Color ExpieredEventColor
{
get
{
object o = ViewState["ExpieredEventColor"];
if (o == null)
return Color.Empty;
else
return (Color)o;
}

set
{
ViewState["ExpieredEventColor"] = value;
}
}
#endregion

#region Add/Remove Date Functionality
public void AddEventDate(DateTime dt)
{
object o = ViewState["EventDates"];
ArrayList dtArray;
if (o == null)
dtArray = new ArrayList(10);
else
dtArray = (ArrayList)o;
dtArray.Add(dt);
ViewState["EventDates"] = dtArray;
}

public void AddExpierEventDate(DateTime dt)
{
object o = ViewState["ExpierEventDate"];

ArrayList dtArray;
if (o == null)
dtArray = new ArrayList(10);
else
dtArray = (ArrayList)o;

dtArray.Add(dt);
ViewState["ExpierEventDate"] = dtArray;
}

public void RemoveEventDate(DateTime dt)
{
object o = ViewState["EventDates"];
ArrayList dtArray;
if (o == null)
dtArray = new ArrayList(10);
else
dtArray = (ArrayList)o;
dtArray.Remove(dt);
ViewState["EventDates"] = dtArray;
}

public void RemoveExpierEventDate(DateTime dt)
{
object o = ViewState["ExpierEventDates"];
ArrayList dtArray;
if (o == null)
dtArray = new ArrayList(10);
else
dtArray = (ArrayList)o;
dtArray.Remove(dt);
ViewState["ExpierEventDates"] = dtArray;
}

private ArrayList EventDates
{
get
{
object o = ViewState["EventDates"];
ArrayList dtArray = (ArrayList)o;
return dtArray;
}
}

private ArrayList ExpierEventDates
{
get
{
object o = ViewState["ExpierEventDates"];
ArrayList dtArray = (ArrayList)o;
return dtArray;
}
}

#endregion Add/Remove Date Functionality
protected override void OnPreRender(object sender,
DayRenderEventArgs e)
{
//Set event day style
Style eventDateStyle = new Style();
eventDateStyle.BackColor = this.EventColor;
eventDateStyle.Font.Bold = true;

//Set expiered event day style
Style expieredEventDateStyle = new Style();
expieredEventDateStyle.BackColor = this.ExpieredEventColor;
expieredEventDateStyle.Font.Bold = true;

//Check for date is event day
if ((IsEventDay(e.Day.Date)))
{
e.Cell.ApplyStyle(eventDateStyle);
}
//Check for date is expiered event day
else if ((IsExpieredEventDay(e.Day.Date)))
{
e.Cell.ApplyStyle(expieredEventDateStyle);
}
}

private bool IsEventDay(DateTime dt)
{
foreach (DateTime dt1 in this.EventDates)
if ((dt1 == dt))
return true;

return false;
}

private bool IsExpieredEventDay(DateTime dt)
{
foreach (DateTime dt1 in this.ExpieredEventDates)
if ((dt1 == dt))
return true;

return false;
}

}

}

Mar 28 '06 #1
4 3916
Hi,

You can override the OnDayRender handler rather than use OnPreRender
because you have easy access to the particular day that is being
rendered in DayRenderEventArgs.

Protected Overrides Sub OnDayRender(s As Object, e As
DayRenderEventArgs)

If IsEventDay(e.Day.Date) Then
'Apply styling to event.
e.Cell.Font.Bold = True
e.Cell.BackColor = Me.EventColor
Else If IsExpiredEventDay(e.Day.Date) Then
'Apply styling to expired event.
e.Cell.BackColor = Me.ExpiredEventColor
End If

End Sub

Good Luck.

Mar 28 '06 #2
Hi,

Thank you for ur quick response.
I agree with you.
But how do i override OnDayRender event. it's not a virtual method of
my base class that is web.ui.controls.calendar

I am getting following error.

EventCalendarControl.OnDayRender(object,
System.Web.UI.WebControls.DayRenderEventArgs)': no suitable method
found to override

Thanks & Regards,
Rushikesh

Ca**********@gmail.com wrote:
Hi,

You can override the OnDayRender handler rather than use OnPreRender
because you have easy access to the particular day that is being
rendered in DayRenderEventArgs.

Protected Overrides Sub OnDayRender(s As Object, e As
DayRenderEventArgs)

If IsEventDay(e.Day.Date) Then
'Apply styling to event.
e.Cell.Font.Bold = True
e.Cell.BackColor = Me.EventColor
Else If IsExpiredEventDay(e.Day.Date) Then
'Apply styling to expired event.
e.Cell.BackColor = Me.ExpiredEventColor
End If

End Sub

Good Luck.


Mar 28 '06 #3
Hi,

Thank you for ur quick response.
I agree with you.
But how do i override OnDayRender event. it's not a virtual method of
my base class that is web.ui.controls.calendar

I am getting following error.

EventCalendarControl.OnDayRender(object,
System.Web.UI.WebControls.DayRenderEventArgs)': no suitable method
found to override.

I think for that i have to use below code...

protected virtual void OnDayRender(TableCell cell, CalendarDay day)
{
if (IsDocumentedDay(day.Date))
{
cell.Font.Bold = true;
cell.BackColor = this.DocumentedColor;
}
else if(IsNotDocumentedDay(day.Date))
{
cell.Font.Bold = true;
cell.BackColor = this.NotDocumentedColor;
}
}

But question is when ll this OnDayRender event call.

this event is not calling in my custom control.

Thanks & Regards,
Rushikesh

Ca**********@gmail.com wrote:
Hi,

You can override the OnDayRender handler rather than use OnPreRender
because you have easy access to the particular day that is being
rendered in DayRenderEventArgs.

Protected Overrides Sub OnDayRender(s As Object, e As
DayRenderEventArgs)

If IsEventDay(e.Day.Date) Then
'Apply styling to event.
e.Cell.Font.Bold = True
e.Cell.BackColor = Me.EventColor
Else If IsExpiredEventDay(e.Day.Date) Then
'Apply styling to expired event.
e.Cell.BackColor = Me.ExpiredEventColor
End If

End Sub

Good Luck.


Mar 28 '06 #4
You're correct.
So you'll have to hook onto the DayRender event and do your
customisation within the handler.

Eg. Assuming you're subclassing calendar directly.

Public Sub New()
AddHandler Me.DayRender, AddressOf MyDayRender
End Sub

Private Sub MyDayRender(ByVal s As Object, ByVal e As
DayRenderEventArgs)
If e.Day.IsToday Then
e.Cell.BackColor = Drawing.Color.AliceBlue
End If
End Sub

Mar 28 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
4583
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...
3
1078
by: Jeti [work] | last post by:
I have made simple control which contains one Calendar control. The problem is that the Calendar control does not behave correctly (doesn't have hyperlinks) when my control renders... here's some...
1
2332
by: Greg Ellis | last post by:
I'm trying to find a way to loop through the Calendar Control and add business days next to each day in the calendar after the SelectedDate. Example: if a user selects May 2nd 2005, I want the...
0
806
by: Don | last post by:
I've noticed some odd behaviour with the .NET calendar control. When a user has Office XP installed on their machine, the calendar is significantly narrower that if the user does not have Office...
1
2211
by: Cong | last post by:
Hi I have two unbounded text boxes (startdate and enddate). If I entered the date manually I can can set validation for the text box for example < date() this will works but if I have a...
2
2109
by: Jason James | last post by:
Hi all, I use a calendar control in an ASP.NET form that is used to capture the date of a specific task. I want to be able to show this date at some future point in time by setting the...
0
991
by: Laz | last post by:
I need some assistance. I am getting the error "Conversion from type 'DBNull' to type 'Date' is not valid." while rendering the edit template column of a calendar control where the SQL field is...
1
1015
by: prateek | last post by:
Hi all. I am working with VB6. I am using Microsoft Calendar Control 8.0 to enter date in a text box. as it is working fine . After i took it to another machine , clicking on the calendar causes...
1
2394
by: Bobby | last post by:
Hello, I'm trying to use the calendar control in access 2003. I go to the tool box and click on more controls, then Calendar control 10. I go to my form and try to insert the control. The screen...
0
7157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7195
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6873
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4889
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4579
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1400
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
644
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
285
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.