Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calendar - extra week displayed 1

Status
Not open for further replies.

ShikkurDude

Programmer
Mar 15, 2005
55
US
My Calendar control always displays 6 weeks per month. I understand one extra is for the partial week that's in this month and part of it's in the other (prior or next) month, but there's always yet another week that's totally in the next (or previous) month. How do I get rid of that completely extra week?

Thanks,
E.
 
The reason that I asked earlier on for the format of your calendar (e.g. Mon, Tue, Wed or Sun, Mon, Tue) is so that we could have avoided this confusion. I stated that my calendar was Mon, Tue, Wed.

I've changed my settings so that the calendar is in the same format, and (for the month of May 2005) without the DayRender event I get:

Sun Mon Tue Wed Thu Fri Sat
24 25 26 27 28 29 30
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31 1 2 3 4

but when I add the following event:

Code:
    Private Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar1.DayRender

        Select Case CurrentCellID
            Case 1
                If e.Day.IsOtherMonth = True And e.Day.Date.AddDays(7).Day = 1 Then
                    blnRemoveFirstRow = True
                    e.Cell.Controls.RemoveAt(0)
                End If

            Case 2 To 7
                If blnRemoveFirstRow = True Then
                    e.Cell.Controls.RemoveAt(0)
                End If

            Case 36
                If e.Day.IsOtherMonth = True Then
                    blnRemoveLastRow = True
                    e.Cell.Controls.RemoveAt(0)
                End If

            Case 37 To 42
                If blnRemoveLastRow = True Then
                    e.Cell.Controls.RemoveAt(0)
                End If

        End Select
        CurrentCellID += 1
    End Sub
I get:

Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31 1 2 3 4

I presume this is what you are looking for?

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
What you get it exactly what I'm looking for. But in addition to what you get, my calendar is preceeded with the entire last week of April! I've recopied your code into mine and still get that.

How frustrating!
E.
 
Was there ever a resolution in removing the extra week? I tried reading through the thread and it seems that in remained unresolved. Does anyone have any ideas how to get that extra week off?

Dot
 
Have you tried it? The whole point of my code was that it was a working example...

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
Ca8msm, yes, I did. But I'm getting exactly what shikurdude got:
What you get is exactly what I'm looking for. But in addition to what you get, my calendar is preceeded with the entire last week of April! I've recopied your code into mine and still get that.

Dot
 
Yes, it is exactly that. But the first week that shows up on my calendar is the last week in April... I am getting the last week of April and then the 5 weeks you are showing. I'm always displaying 6 weeks on every month...

Dot
 
Your not using the my code above then. That project is at home. I will submit a link to it later
 
Hmmm...this is strange...below is an image I've taken from my pc when I run the same page from my localhost and then when I view it via the remote address:
calendar.jpg

As you can see from the image, the calendar displays fine from the localhost but not from the remote address (which is why I guess some of you have been having problems).

As RTomes is going to provide you with an alternative method, I suggest you look at that whilst I figure why there is a difference.

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
Ca8msm, I'm giving you a star for a good discovery. (Seems significant, at least.) Now the question is why!

rTomes?

Thanks,
Dot
 
This hides the TR tag on the client.
I could not find a way to completely omit the <TR> tag in calender.

ASPX PAGE:
Code:
<%@ Page Language="vb" AutoEventWireup="false" src="CalendarHideWeeks.aspx.vb" inherits="CalendarHideWeeks"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
	<HEAD>
		<title>CalendarHideWeeks</title>
		<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
		<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
		<meta name="vs_defaultClientScript" content="JavaScript">
		<meta name="vs_targetSchema" content="[URL unfurl="true"]http://schemas.microsoft.com/intellisense/ie5">[/URL]
	</HEAD>
	<body>
		<form id="Form1" method="post" runat="server">
			<asp:Calendar id="Calendar1" runat="server"  ></asp:Calendar>
		</form>
	</body>
</HTML>

VB CODE BEHIND:
Code:
Imports Microsoft.visualbasic
Imports System.Web.UI.WebControls
Imports System.Web
Imports System.Web.ui
Imports System


Public Class CalendarHideWeeks

    Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents Calendar1 As System.Web.UI.WebControls.Calendar

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        Me.Calendar1.VisibleDate = Now
    End Sub
    Private Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar1.DayRender
        If e.Day.Date.DayOfWeek = DayOfWeek.Sunday Then
            If e.Day.Date.Month <> CType(sender, Calendar).VisibleDate.Month And _
            e.Day.Date.AddDays(6).Month <> CType(sender, Calendar).VisibleDate.Month Then
                Dim lit As New Literal
                lit.Text = "<script id='" & e.Day.Date.Ticks.ToString & "'>window.setTimeout('document.getElementById(\'" & e.Day.Date.Ticks.ToString & "\').parentNode.parentNode.style.display=\'none\'',50);</script>"
                e.Cell.Controls.Add(lit)
            End If
        End If

    End Sub
End Class



I don't think you should have to download something this basic, but here it is just in case you have any problems.


I put up Ca8msm's example ( ) to try to reproduce the strange error. I did not run into any issues,but I do believe the problem.

I have Ca8msm's example all in one page at that address.
Code:
<%@ Page %>
<%@ Import NameSpace="System.Web.UI.WebControls" %>
<%@ Import NameSpace="MicroSoft.VisualBasic" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<script runat=server>
	Dim CurrentCellID As Integer = 1
    Dim blnRemoveFirstRow As Boolean = False
    Dim blnRemoveLastRow As Boolean = False

	Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) 
        'Put user code to initialize the page here
        Me.Calendar1.VisibleDate = Now
    End Sub
   

    Public Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) 

        Select Case CurrentCellID
            Case 1
                If e.Day.IsOtherMonth = True And e.Day.Date.AddDays(7).Day = 1 Then
                    blnRemoveFirstRow = True
                    e.Cell.Controls.RemoveAt(0)
                End If

            Case 2 To 7
                If blnRemoveFirstRow = True Then
                    e.Cell.Controls.RemoveAt(0)
                End If

            Case 36
                If e.Day.IsOtherMonth = True Then
                    blnRemoveLastRow = True
                    e.Cell.Controls.RemoveAt(0)
                End If

            Case 37 To 42
                If blnRemoveLastRow = True Then
                    e.Cell.Controls.RemoveAt(0)
                End If

        End Select
        CurrentCellID += 1
    End Sub

</script>
<HTML>
	<body MS_POSITIONING="GridLayout">
		<form id="Form1" method="post" runat="server">
			<asp:Calendar OnDayRender="Calendar1_DayRender" id="Calendar1" style="Z-INDEX: 101; LEFT: 76px; POSITION: absolute; TOP: 52px" runat="server"></asp:Calendar>
		</form>
	</body>
</HTML>
 
rTomes, I read over your last post several times. I hate to sound like an idiot, but where does this leave us? (I know how dumb that sounds!)

Dot
 
If this ( ) hides the weeks then the example above will work.

I don't know why C8msm's example will not work for them, it works for me.
I put his all in one aspx page to try to remove an chance of error.
If I have my choice I would rather do it Ca8msm's because it does not rely on client side scripting. It does leave empty <td></td> tags which use to break IE in the past.

The reason Ca8msm's produces different results may have something to do with regional settings being different on the two different machines.
 
rTomes and Ca8msm, you've spent so much time on this, I'd really like to get it working...

I still can't get it working. My DayRender calls the following:
Code:
	Private Sub RemoveExtraWeek(ByVal sender As System.Object, ByRef e As System.Web.UI.WebControls.DayRenderEventArgs)

		Select Case CurrentCellID
			Case 1
				If e.Day.IsOtherMonth = True And e.Day.Date.AddDays(7).Day = 1 Then
					blnRemoveFirstRow = True
					e.Cell.Controls.RemoveAt(0)
				End If

			Case 2 To 7
				If blnRemoveFirstRow = True Then
					e.Cell.Controls.RemoveAt(0)
				End If

			Case 36
				If e.Day.IsOtherMonth = True Then
					blnRemoveLastRow = True
					e.Cell.Controls.RemoveAt(0)
				End If

			Case 37 To 42
				If blnRemoveLastRow = True Then
					e.Cell.Controls.RemoveAt(0)
				End If

		End Select
		CurrentCellID += 1

	End Sub
Am I missing something?

Thanks for both of your big efforts! I do appreciate them much!
Dot
 
As expained above, both examples above work for me.
Two people said they had problems with ca8msms.
What more do you need to know?
 
I just don't get it rTomes... :-(

I have the following sub being called unconditionally in DayRender:
Code:
	Private Sub RemoveExtraWeek(ByVal sender As System.Object, ByRef e As System.Web.UI.WebControls.DayRenderEventArgs)
		If e.Day.Date.DayOfWeek = DayOfWeek.Sunday Then
			If e.Day.Date.Month <> CType(sender, Calendar).VisibleDate.Month And _
			e.Day.Date.AddDays(6).Month <> CType(sender, Calendar).VisibleDate.Month Then
				Dim lit As New Literal
				lit.Text = "<script id='" & e.Day.Date.Ticks.ToString & "'>window.setTimeout('document.getElementById(\'" & e.Day.Date.Ticks.ToString & "\').parentNode.parentNode.style.display=\'none\'',50);</script>"
				e.Cell.Controls.Add(lit)
			End If
		End If
	End Sub
...and I'm still getting 6 weeks per calendar!

:-( :-( :-( Dot
 
Try this simplified approach.

Code:
Private Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar1.DayRender
        If e.Day.Date.Month <> CType(sender, Calendar).VisibleDate.Month Then
            'e.Cell.Text = "N/A" 'Try just writing in the cell here.
            e.Cell.Style("display") = "none"

            'or use Ca8msm's line here. Both work.
            'e.Cell.Controls.RemoveAt(0)
        End If
    End Sub

Run in debug and set break point at
If e.Day.Date.Month
and see if the Day_Render event is even firing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top