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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

calendar 2

Status
Not open for further replies.

kebele

MIS
Jul 31, 2006
107
US
Hi all,
I am working with calendar control and when the user select the year from the link i create for calendar control i do not want them go beyond the year 2007. how can this be done. thanks for the help.


<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
<script runat="server">
Sub calEventDate_SelectionChanged(ByVal sender As Object, ByVal e As EventArgs)
StartDateStr.Text = calEventDate.SelectedDate.ToString("d")
calEventDate.Visible = False
End Sub
Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
calEventDate.Visible = True
End Sub
</script>

<html xmlns=" >
<head>
<title>Calendar </title>
</head>
<body>
<form id="form1" runat="server">
<asp:TextBox id="StartDateStr" Runat="server" Style="width:190px" />
<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">Calendar</asp:LinkButton>
<asp:Calendar id="calEventDate" OnSelectionChanged="calEventDate_SelectionChanged" Visible=False Runat="server" />
</form>
</body>
</html>
 
I just don't see how you can reference that particular cell to apply the style
 
As jbenson001 suggested it can not be possible to reference that particular cell....Well for now I should stick with what i have. Thank you all for the tip and help.
Have a blessed weekend!
 
checking the text contents of the cell would be one way.
 
An easier way would be to use the VisibleMonthChanged and check which month and year are being shown. If it equals the last month and year that you want to show, simply set the NextMonthText to an empty String i.e.
Code:
    Protected Sub Calendar1_VisibleMonthChanged(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MonthChangedEventArgs) Handles Calendar1.VisibleMonthChanged
        If e.NewDate.Year = 2007 And e.NewDate.Month = 12 Then
            Calendar1.NextMonthText = ""
        End If
    End Sub


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
thanks for that ca8msm, never used that existed :) now i do
 
It's a bit of a shame that we have to resort to doing this though - the windows MonthCalendar control has MinDate and MaxDate properties that you can set so it would have been nice if they had been included these in the ASP.NET Calendar control.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Thank you all, I learned a lot from you.
I just used code form ca8msm and I am just wondering how to get back the ">" when a year is not equal to 2007. I just added calEventDate.NextMonthText = calEventDate.ShowNextPrevMonth and does not work ...any clue. thanks a bunch


Protected Sub calEventDate_VisibleMonthChanged(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MonthChangedEventArgs)
If e.NewDate.Year = 2007 And e.NewDate.Month = 12 Then
calEventDate.NextMonthText = ""
Else
calEventDate.NextMonthText = calEventDate.ShowNextPrevMonth
End If
End Sub
 
If you need to set the value of a property to a ">", then that's exactly what you do e.g
Code:
    Protected Sub Calendar1_VisibleMonthChanged(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MonthChangedEventArgs) Handles Calendar1.VisibleMonthChanged
        If e.NewDate.Year = 2007 And e.NewDate.Month = 12 Then
            Calendar1.NextMonthText = ""
        Else
            [b]Calendar1.NextMonthText = ">"[/b]
        End If
    End Sub


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Here is the entire code for someone who want to work with calender.


<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
<script runat="server">
Sub calEventDate_SelectionChanged(ByVal sender As Object, ByVal e As EventArgs)
StartDateStr.Text = calEventDate.SelectedDate.ToString("MM/dd/yyyy")
calEventDate.Visible = False
End Sub
Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
calEventDate.Visible = True
End Sub
Protected Sub calEventDate_VisibleMonthChanged(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MonthChangedEventArgs)
If e.NewDate.Year = 2006 And e.NewDate.Month = 12 Then
calEventDate.NextMonthText = ""

Else
calEventDate.NextMonthText = ">"
End If

If e.NewDate.Year = 2005 And e.NewDate.Month = 12 Then
calEventDate.PrevMonthText = ""
Else
calEventDate.PrevMonthText = "<"
End If
End Sub

Protected Sub calEventDate_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs)
If (e.Day.Date.Year > "2006" Or e.Day.Date.Year < "2005") Then
e.Cell.Enabled = False
e.Day.IsSelectable = False
End If

End Sub


</script>


<html xmlns=" >
<head>

<title>Calendar </title>
</head>
<body>
<form id="form1" runat="server">
<strong>
<br />
Beg. Date: </strong>
<asp:TextBox id="StartDateStr" Runat="server" BackColor="White" BorderStyle="Solid" Width="144px" />
<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click" Font-Bold="True" Font-Italic="True" EnableViewState="False" Font-Size="Medium" Font-Underline="True">Calendar</asp:LinkButton>
<asp:Calendar id="calEventDate"
OnSelectionChanged="calEventDate_SelectionChanged"
Visible=False Runat="server" BackColor="#FFFFCC" BorderColor="#FFCC66" BorderWidth="1px" Font-Names="Verdana" Font-Size="8pt" ForeColor="#663399" Height="200px" Width="220px"
style="color: black; background-color: ghostwhite; position: absolute;" DayNameFormat="Shortest" ShowGridLines="True"
OnVisibleMonthChanged="calEventDate_VisibleMonthChanged" OnDayRender="calEventDate_DayRender">

<SelectedDayStyle BackColor="#CCCCFF" Font-Bold="True" />
<TodayDayStyle BackColor="#FFCC66" ForeColor="White" />
<OtherMonthDayStyle ForeColor="#CC9966" />
<NextPrevStyle Font-Size="9pt" ForeColor="#FFFFCC" />
<DayHeaderStyle Font-Bold="True" BackColor="#FFCC66" Height="1px" />
<TitleStyle BackColor="#990000" Font-Bold="True" Font-Size="9pt" ForeColor="#FFFFCC" />
<SelectorStyle BackColor="#FFCC66" />
</asp:Calendar>
</form>
</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top