473,614 Members | 2,335 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem in rendering the calendar control

Hi All,

I want to create custom control by using Web.UI.WebContr ols.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(obj ect sender, DayRenderEventA rgs 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 EventCalendarCo ntrol
*************** ***////////////////

using System;
using System.Collecti ons.Generic;
using System.Componen tModel;
using System.Collecti ons;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Drawing;
namespace MACT.Controls
{
[ToolboxData("<{ 0}:EventCalenda rControl
runat=server></{0}:EventCalend arControl>")]
public class EventCalendarCo ntrol :
System.Web.UI.W ebControls.Cale ndar
{
[Bindable(true),
Category("Appea rance"),
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 ExpieredEventCo lor
{
get
{
object o = ViewState["ExpieredEventC olor"];
if (o == null)
return Color.Empty;
else
return (Color)o;
}

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

#region Add/Remove Date Functionality
public void AddEventDate(Da teTime 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 AddExpierEventD ate(DateTime dt)
{
object o = ViewState["ExpierEventDat e"];

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

dtArray.Add(dt) ;
ViewState["ExpierEventDat e"] = 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 RemoveExpierEve ntDate(DateTime dt)
{
object o = ViewState["ExpierEventDat es"];
ArrayList dtArray;
if (o == null)
dtArray = new ArrayList(10);
else
dtArray = (ArrayList)o;
dtArray.Remove( dt);
ViewState["ExpierEventDat es"] = dtArray;
}

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

private ArrayList ExpierEventDate s
{
get
{
object o = ViewState["ExpierEventDat es"];
ArrayList dtArray = (ArrayList)o;
return dtArray;
}
}

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

//Set expiered event day style
Style expieredEventDa teStyle = new Style();
expieredEventDa teStyle.BackCol or = this.ExpieredEv entColor;
expieredEventDa teStyle.Font.Bo ld = true;

//Check for date is event day
if ((IsEventDay(e. Day.Date)))
{
e.Cell.ApplySty le(eventDateSty le);
}
//Check for date is expiered event day
else if ((IsExpieredEve ntDay(e.Day.Dat e)))
{
e.Cell.ApplySty le(expieredEven tDateStyle);
}
}

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

return false;
}

private bool IsExpieredEvent Day(DateTime dt)
{
foreach (DateTime dt1 in this.ExpieredEv entDates)
if ((dt1 == dt))
return true;

return false;
}

}

}

Mar 28 '06 #1
4 3921
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 DayRenderEventA rgs.

Protected Overrides Sub OnDayRender(s As Object, e As
DayRenderEventA rgs)

If IsEventDay(e.Da y.Date) Then
'Apply styling to event.
e.Cell.Font.Bol d = True
e.Cell.BackColo r = Me.EventColor
Else If IsExpiredEventD ay(e.Day.Date) Then
'Apply styling to expired event.
e.Cell.BackColo r = Me.ExpiredEvent Color
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.

EventCalendarCo ntrol.OnDayRend er(object,
System.Web.UI.W ebControls.DayR enderEventArgs) ': no suitable method
found to override

Thanks & Regards,
Rushikesh

Ca**********@gm ail.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 DayRenderEventA rgs.

Protected Overrides Sub OnDayRender(s As Object, e As
DayRenderEventA rgs)

If IsEventDay(e.Da y.Date) Then
'Apply styling to event.
e.Cell.Font.Bol d = True
e.Cell.BackColo r = Me.EventColor
Else If IsExpiredEventD ay(e.Day.Date) Then
'Apply styling to expired event.
e.Cell.BackColo r = Me.ExpiredEvent Color
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.

EventCalendarCo ntrol.OnDayRend er(object,
System.Web.UI.W ebControls.DayR enderEventArgs) ': no suitable method
found to override.

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

protected virtual void OnDayRender(Tab leCell cell, CalendarDay day)
{
if (IsDocumentedDa y(day.Date))
{
cell.Font.Bold = true;
cell.BackColor = this.Documented Color;
}
else if(IsNotDocumen tedDay(day.Date ))
{
cell.Font.Bold = true;
cell.BackColor = this.NotDocumen tedColor;
}
}

But question is when ll this OnDayRender event call.

this event is not calling in my custom control.

Thanks & Regards,
Rushikesh

Ca**********@gm ail.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 DayRenderEventA rgs.

Protected Overrides Sub OnDayRender(s As Object, e As
DayRenderEventA rgs)

If IsEventDay(e.Da y.Date) Then
'Apply styling to event.
e.Cell.Font.Bol d = True
e.Cell.BackColo r = Me.EventColor
Else If IsExpiredEventD ay(e.Day.Date) Then
'Apply styling to expired event.
e.Cell.BackColo r = Me.ExpiredEvent Color
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(ByV al s As Object, ByVal e As
DayRenderEventA rgs)
If e.Day.IsToday Then
e.Cell.BackColo r = Drawing.Color.A liceBlue
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
4594
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 Color 3. Foreground Color 4. Border Tickness 5. Border Color
3
1084
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 of the code: public class MyControl { private Calendar _calendar; protected override void CreateChildControls()
1
2341
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 calendar to display |3-1|, |4-2|, |5-3|...etc. I created a loop to display this. However, the loop is running first before rendering it. It looks like |3-1-2-3-4-5|, |4-1-2-3-4-5|, |5-1-2-3-4-5|...etc. I currently have the loop set from 1 to 5,...
0
821
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 XP installed. I've been told this is because the .NET calender is just a wrapper for the older calendar that is part of the common controls ActiveX components, and Office XP update these components. Is there anyway to overcome this problem? Is...
1
2218
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 calendar control populating the date automaticcaly. It will bypass the validation. I try this for validation but does not
2
2115
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 SelectedDate of the calendar control to the value returned from a database. This all works fine and the selected date is indeed highlighted. However, if the date of the task is not in the current month then I have to navigate to the correct month of...
0
998
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 null. Here is the column code: <ASP:TemplateColumn HEADERTEXT="Planned Date" ITEMSTYLE-HORIZONTALALIGN="Center"> <ItemTemplate>
1
1021
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 VB error and VB closes down. Can you help me. Prateek
1
2405
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 freezes for a few minutes and then the application crashes, with the option of sending a report to microsoft. Any ideas? It's happened several times, despite a re-boot. Thanks
0
8197
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8640
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8589
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8287
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6093
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4058
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4136
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2573
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 we have to send another system
0
1438
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.