Help with calendar control.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • markclinn
    New Member
    • Feb 2007
    • 7

    Help with calendar control.

    I am trying to use the calander control to pick a date and retrieve information from a database. When a date is clicked on, the page re-loads, with the selected date, gets the informatino from the database and creates a graph. The problem that I am having is that when you pick the "<" or ">" to navigate to a new month the page reloads with the current month. How do I get around this?

    Code:
    <%@ Page Language="VB" %>
    <script language="VB" runat="server">
    
        Dim MyVal1 As Boolean
        Dim SelectedDate As Date
        Dim testt As String
        
        Sub Page_Load()
            
            Try
                MyVal1 = Convert.ToBoolean(Request("checkbox1"))
            Catch
                MyVal1 = True
            End Try  
                      
        End Sub
        
        Function GetmyDate() As String
            
            If Calendar1.SelectedDate.Date.ToShortDateString = "1/1/0001" Then
                GetmyDate = Now.ToShortDateString
            Else
                GetmyDate = Calendar1.SelectedDate.Date.ToShortDateString
            End If
    
            Calendar1.VisibleDate = GetmyDate
             
        End Function
    
    </script>
    <html>
    <head id="Head1" runat="server">
    </head>
    <body scroll="auto">
        <form id="form1" runat="server">
            <strong><span style="font-size: 24pt"> <br /></span></strong>
            <br />
            The Date is: <%= GetmyDate%>
            <br />
            <Img ID="Image1" src="Draw_Pic.ASPX?val1=<%= MyVal1%>&val2=<%= GetmyDate%>" width=768 height=375><br />
            <strong><span style="font-size: 12pt"> <br /></span></strong>
            <strong><span style="font-size: 12pt"> <br /></span></strong>
            <strong><span style="font-size: 12pt"><br /></span></strong>
            <br />
            <asp:CheckBox ID="CheckBox1" runat="server" Font-Size="12pt" style="z-index: 104; left: 121px; position: absolute; top: 539px" />&nbsp; &nbsp;<br />
                <br />         
                <asp:Calendar ID="Calendar1" runat="server" Font-Names="Arial" Font-Size="12pt" Height="200px" Width="200px" BackColor="WhiteSmoke" BorderColor="Black" BorderWidth="3px" DayNameFormat="FirstLetter" EnableViewState="False" style="z-index: 105; left: 12px; position: absolute; top: 570px" >
                    <TodayDayStyle BorderWidth="3px" BackColor="MistyRose" BorderColor="Red" />
                    <DayStyle BorderStyle="Ridge" BorderWidth="1px" BackColor="WhiteSmoke" />
                    <DayHeaderStyle BackColor="DarkGray" BorderStyle="Ridge" BorderWidth="1px" BorderColor="Black" />
                    <TitleStyle Font-Bold="True" BackColor="LightSteelBlue" />
                    <WeekendDayStyle BackColor="#E0E0E0" />
                    <OtherMonthDayStyle BackColor="Silver" BorderColor="DimGray" BorderStyle="Solid"
                        BorderWidth="1px" />
                </asp:Calendar>
            <br />
            <br />
                <asp:Button ID="Button1" runat="server" Text="Button" style="z-index: 110; left: 231px; position: absolute; top: 536px" />
            <br />
            &nbsp;<br />
        </form>
    
    </body>
    </html>
  • jhardman
    Recognized Expert Specialist
    • Jan 2007
    • 3405

    #2
    I may be way off, you write in a bit of a different style than I, but it looks like you load the page and then ask which date is entered. In the getmydate function you need to refer to the date picked on the last screen, not the current one. I would have the link look something like this:
    Code:
    <%
    dim prevDate, nexDate
    prevDate = dateAdd("m", -1, date)
    nexDate = dateAdd("m", 1, date)
    %>
    <a href="thispage.asp?myDate=<%=urlEncode(prevDate)%>">&lt;</a>
    <a href="thispage.asp?myDate=<%=urlEncode(nexDate)%>">&gt;</a>
    and then the page that opens it should say:
    Code:
    dim getMyDate
    getMyDate = date
    if request("myDate") <> ""  then getMyDate = request("myDate")

    Comment

    Working...