codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  ASP.NET calendar help  leeyoung at 11:38 on Thursday, October 21, 2004
 

<%@ Language=VBScript %>
<%Option Explicit%>
<%
Dim m_dtCurrentDate 'Currently selected date/time
Dim m_lDayofFirst 'The day of the week that the first of the current month falls on
Dim m_lDaysInMonth 'Number of days in the selected month
Dim m_dtBegin 'Beginning date of the selected month
Dim m_dtEnd 'Ending date of the selected month

Dim m_lYear 'Currently selected Year
Dim m_lMonth 'Currently selected Month
Dim m_lDay 'Currently selected Day of the month
Dim m_lHour 'Currently selected Hour
Dim m_lMinute 'Currently selected minute
Dim m_sAMPM 'Currently selected AM/PM

Dim m_sInputName 'Name of the input field from the parent page
Dim m_dtPassedInDate

m_sInputName = Request.QueryString("N")

'Build the date/time from individual parts if there has been a post back.
'Otherwise, just get the current date/time.
If Request.QueryString("A") <> "" Then
m_lYear = Request.Form("fldYear")
m_lMonth = Request.Form("fldMonth")
m_lDay = Request.Form("fldDay")
m_lHour = Request.Form("fldHour")
m_lMinute = Request.Form("fldMinute")
m_sAMPM = Request.Form("fldAMPM")

'Fix the day of the month if we switch from a month that has less days in the month
'than the previously selected month and the day selected is not on the newly selected
'month (ie - going from March 31st and then selecting February which does not have a 31st.)
m_dtBegin = m_lMonth & "/1/" & m_lYear
m_dtEnd = DateAdd("m", 1, m_dtBegin)
m_lDaysInMonth = DateDiff("d", m_dtBegin, m_dtEnd)
If CLng(m_lDay) > CLng(m_lDaysInMonth) Then m_lDay = m_lDaysInMonth

'Build the Date
m_dtCurrentDate = m_lMonth & "/index.html" & m_lDay & "/index.html" & m_lYear
m_dtCurrentDate = m_dtCurrentDate & " " & m_lHour & ":" & m_lMinute & ":00 " & m_sAMPM

'If the date is not valid after all this then use the current date.
If IsDate(m_dtCurrentDate) Then
m_dtCurrentDate = CDate(m_dtCurrentDate)
Else
m_dtCurrentDate = Now()
End If

Else
m_dtPassedInDate = Request.QueryString("DT")
If CStr(m_dtPassedInDate) <> "" Then
If IsDate(m_dtPassedInDate) Then
m_dtCurrentDate = CDate(m_dtPassedInDate)
Else
m_dtCurrentDate = Now()
End If
Else
m_dtCurrentDate = Now()
End If
End If

'Break out certain parts of the currently selected date/time.
m_lYear = DatePart("yyyy", m_dtCurrentDate)
m_lMonth = DatePart("m", m_dtCurrentDate)
m_lDay = DatePart("d", m_dtCurrentDate)
m_lHour = DatePart("h", m_dtCurrentDate)
m_lMinute = DatePart("n", m_dtCurrentDate)

'Figure out if we need an AM or PM
If CLng(m_lHour) > 12 Then
m_lHour = m_lHour - 12
m_sAMPM = "PM"
ElseIf CLng(m_lHour) = 12 Then
m_sAMPM = "PM"
ElseIf CLng(m_lHour) = 0 Then
m_lHour = 12
m_sAMPM = "AM"
Else
m_sAMPM = "AM"
End If

m_dtBegin = CDate(DatePart("m", m_dtCurrentDate) & "/1/" & DatePart("yyyy", m_dtCurrentDate))
m_dtEnd = DateAdd("m", 1, m_dtBegin)
m_lDayofFirst = DatePart("w", m_dtBegin)
m_lDaysInMonth = DateDiff("d", m_dtBegin, m_dtEnd)
%>
<HTML>
<HEAD>
<TITLE>Choose a date/time</TITLE>
<LINK rel="stylesheet" type="text/css" href="/forum/Calendar.css">
</HEAD>
<BODY bgcolor="#D4D0C8">
<FORM method=post action="/forum/Calendar_A_1_ampN__lt_m_sInputName_gt_.html" id=Form1 name=Form1>
<table class=overall cellpadding=0 cellspacing=10>
<tr>
<td>
<%DisplayCalendar%>
</td>
<td valign=top>
<table>
<tr>
<td class="Title">
Month:<BR>
</td>
<td class="Title">
Year:<BR>
</td>
</tr>
<tr>
<td>
<SELECT id=fldMonth name=fldMonth onchange="javascript:document.Form1.submit();">
<%DisplayMonths%>
</SELECT>
</td>
<td>
<INPUT type="text" id=fldYear name=fldYear value="<%=m_lYear%>" size=3 maxlength=4 onblur="javascript:document.Form1.submit();"><BR>
</td>
</tr>
<tr>
<td colspan=2 class="Title">
Time:<BR>
</td>
</tr>
<tr>
<td colspan=2>
<%DisplayHours%> <B>:</B> <%DisplayMinutes%> <%DisplayAMPM%>
</td>
</tr>
</table>
<BR>
<INPUT type="button" value="OK" id=cmdOK name=cmdOK class=Button onclick="javascript:SetDateOnParent();"> 
<INPUT type="button" value="Cancel" id=cmdCancel name=cmdCancel class=Button onclick="javascript:window.close();">
</td>
</tr>
</table>
</FORM>
</BODY>
</HTML>
<%
Sub DisplayMonths
Dim arrMonths 'An array of months starting with January
Dim i 'counter

arrMonths = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")

For i = 0 To UBound(arrMonths)
If CLng(i) = (CLng(m_lMonth) - 1) Then
Response.Write "<OPTION value=" & i + 1 & " SELECTED>" & arrMonths(i) & "</OPTION>"
Else
Response.Write "<OPTION value=" & i + 1 & ">" & arrMonths(i) & "</OPTION>"
End If
Next
End Sub

Sub DisplayHours
Dim i
Dim sDisplayHour

Response.Write "<select name='fldHour'>"
For i = 1 To 12
If Len(i) = 1 Then
sDisplayHour = "0" & i
Else
sDisplayHour = i
End If

If CInt(i) = CInt(m_lHour) Then
Response.Write "<OPTION value='" & i & "' SELECTED>" & sDisplayHour
Else
Response.Write "<OPTION value='" & i & "'>" & sDisplayHour
End If
Next
Response.Write "</select>"
End Sub

Sub DisplayMinutes
Dim i
Dim sDisplayMinute

Response.Write "<select name='fldMinute'>"
For i = 0 To 59
If Len(i) = 1 Then
sDisplayMinute = "0" & i
Else
sDisplayMinute = i
End If

If CInt(i) = CInt(m_lMinute) Then
Response.Write "<OPTION value='" & i & "' SELECTED>" & sDisplayMinute
Else
Response.Write "<OPTION value='" & i & "'>" & sDisplayMinute
End If
Next
Response.Write "</select>"
End Sub

Sub DisplayAMPM
Dim arrAMPM
Dim i

arrAMPM = Array("AM", "PM")

Response.Write "<select name='fldAMPM'>"
For i = 0 To UBound(arrAMPM)
If arrAMPM(i) = CStr(m_sAMPM) Then
Response.Write "<OPTION value='" & arrAMPM(i) & "' SELECTED>" & arrAMPM(i)
Else
Response.Write "<OPTION value='" & arrAMPM(i) & "'>" & arrAMPM(i)
End If
Next
Response.Write "</select>"
End Sub

Sub DisplayCalendar
Dim arrDays 'An array of days starting with Sunday
Dim i 'counter
Dim lColumnCount 'Column Count
Dim lNumber 'For building the calendar
Dim bFinished 'For building the calendar
Dim bStart 'For building the calendar

arrDays = Array("S", "M", "T", "W", "T", "F", "S")

Response.Write "<table width=100 class='Calendar' cellpadding=4 cellspacing=0><tr class=Header>"
For i = 0 to Ubound(arrDays)
Response.write "<td>" & arrDays(i) & "</td>"
Next

lNumber = 1
bFinished = False
bStart = False
Do
Response.Write "<tr>"
For lColumnCount = 1 to 7
If CLng(lColumnCount) = CLng(m_lDayofFirst) Then
bStart = True
End If

If CLng(m_lDay) = CLng(lNumber) AND CBool(bStart) Then
Response.Write "<td class=SelectedDay>"
Response.Write "<input name=fldDay type=hidden value=" & lNumber & ">"
Else
Response.Write "<td class=NormalDay>"
End If

If NOT CBool(bFinished) AND CBool(bStart) Then
If CLng(m_lDay) <> CLng(lNumber) Then
Response.Write "<A href='javascript:ChangeDay(" & lNumber & ");'>"
End If
Response.Write lNumber
If CLng(m_lDay) <> CLng(lNumber) Then
Response.Write "</A>"
End If
lNumber = lNumber + 1
If CLng(lNumber) > CLng(m_lDaysInMonth) Then
bFinished = True
End If
Else
Response.Write " "
End If
Response.Write "</td>"
Next
Response.Write "</tr>"
Loop Until CBool(bFinished)

Response.Write "</tr></table>"
End Sub
%>

<script language="javascript">
function ChangeDay(v_lDay) {
document.Form1.fldDay.value = v_lDay;
document.Form1.submit();
}

function SetDateOnParent() {
var sRetDateTime;
var sHour = document.Form1.fldHour.value;
var sMinute = document.Form1.fldMinute.value;
var sAMPM = document.Form1.fldAMPM.value;

if (sHour.length == 1) {
sHour = '0' + sHour;
}
if (sMinute.length == 1) {
sMinute = '0' + sMinute;
}

sRetDateTime = '<%=FormatDateTime(m_dtCurrentDate, 2)%> ' + sHour + ':' + sMinute + ' ' + sAMPM;
window.opener.eval('<%=m_sInputName%>').value = sRetDateTime;
window.close();
}
</script>

This is my asp page to display a demo calender in ASP. Now I would like to change it in ASP.NET. How can I use .NET class library in my file!
the data of calendar(from year 1900 onward) imported from existing .NET class library
when I change date month year it will reflect new data.
Give me help! Thanks !









CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Re: Help: Trouble with z-Index and SELECT lists
•  What is wrong with this ASP codes? It don`t seem to work???
•  Need help with ListBox control
•  Re: Good Javascript/DHTML Reference
•  Re: scrolling table
•  Re: simulation of road traffic
•  ASP.NET calendar help
•  Re: Hosting Plan or Scam?
•  Re: Source Control


Recent Articles
Communicating with the Database (Using ADO)
MagicGrid
Simple Thumbnail Browsing Solution
Type Anywhere
A Better Moustrap: FmtDate to replace FormatDateTime
ASP.NET Forum Source Code
Internal Search Engine
Javascript Growing Window
Simple date validation
Search engine friendly URLs using ASP.NET (C#.NET)


Site Survey
Help us serve you better. Take a five minute survey. Click here!

© Copyright codetoad.com 2001-2004