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>
 
Code:
Protected Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar1.DayRender
  If e.Day.Date.Year > "2007 then" Then
     e.Cell.Enabled = False
  End If
End Sub

Jim
 
Thanks Jim! I am still able to select year 2008 ....here is an example after i apply your code 01/01/2008. any clue why? It is greyed out but I can still select the value ...
thanks again.
 
e.Cell.Text = ""

Just added this line of code and the calendar does not have any day selection when i select year 2008.The calendar control does not have give the option to select date and it is just blank. It really looks ungly and unprofessional. I wonder if there is a way to disable the arrow for go to next month on the calendar control.
 
Thanks for the reply..
I checked the link you provide to me and come up with this code and still not working for me.I am a little bit furstrated ..I do not know why it is not working.any additional help would be appreciated


Protected Sub calEventDate_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs)
If e.Day.Date.Year.ToString > "2007" Then
calEventDate.ShowNextPrevMonth = False
End If
End Sub
 
have you tried doing this in the OnDataBinding event instead of dayrender?
 
sorry i didn't get back to you sooner. Add this line:
Protected Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar1.DayRender
If e.Day.Date.Year > "2007" Then
e.Cell.Enabled = False
e.Day.IsSelectable = False
End If
End Sub
 
That did for me. as always thanks for the tip and help.
 
One more question ...how hard it is to make this code only to display ">" arrow until 2007 and ShowNextPrevMonth property set to false when someone try to make a selection year beyond 2007..like 2008 and give them a choice only to go back.any idea how this can be done. if it is hard to do it then i probably stick with what i have. thanks again.
 
I don't think you can, because the ShowNextPrevMonth disables both controls. You can probably do this with 3rd party controls. Or maybe there is a downloadable custom control you can find online.

 
You can use a style display:none and apply it to your next month area in the cases that you need to.

 
Thanks tperri for the tip and try to help me out here.
I did create this and I donot know where to add it.

<style type="text/css">
#DisableNexMonth
display:none;
</style>

below is my code for calendar

<%@ 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_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs)
If (e.Day.Date.Year > "2006") Then
e.Cell.Enabled = False
e.Day.IsSelectable = False
End If
End Sub
</script>


<html xmlns=" >
<head>
<style type="text/css">
#DisableNexMonth
display:none;
</style>
<title>Calendar </title>
</head>
<body>
<form id="form1" runat="server">
<strong>
<br />
Beg. Date: </strong>
<asp:TextBox id="StartDateStr" Runat="server" BackColor="White" BorderStyle="Ridge" 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"
OnDayRender="calEventDate_DayRender" style="color: black; background-color: ghostwhite; position: absolute;" DayNameFormat="Shortest" ShowGridLines="True">
<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>
 
Change the style in your code when the dates meet the requirements that you need to disable them.

If you dont know about CSS - look at w3schools.com at a tutorial. Look at display:none for what you need.
 
How is it possible to just diable one or the other? I don't think this is even possible with CSS.
 
If this is possilbe tperri can you give me an example how this can be done?
 
dont disable ShowNextPrevious; use CSS to not display the text from the NextPrevious area.

I cant give you a sample, kebele, I dont have one with me and I dont have time at work to make one. Sorry. Hopefully you can play around with it and figure it out yourself? :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top