How do I create a "date" range using a calendar? VB.NET

Please have a look at this page:  http://www.goodtherapy.org/962.html  note the 'date' search area.  It shows as two text boxes that automatically fill in when you choose a date on an expanded calendar.  The calendars automatically minimize when you choose a date.

how do i create this in VB.NET?  using version 2005

thanks!
arthurh88Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
rhythmluvrConnect With a Mentor Commented:
On my last post you will notice that I also included a month and year listbox, useful if the user wants to jump around in the calendar.

Ok, this post is the code-behind page that controls the calendar.aspx page when called. This is in c# but you should be able to translate to vb without much problems.
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
 
public partial class calendar : System.Web.UI.Page
{
    protected void Page_LoadComplete(object sender, EventArgs e)
    {
        //Populate year and month listbox
        if (Page.IsPostBack == false)
        {
            int intYear ;          
            for(intYear = Convert.ToInt16(DateTime.Now.Year) - 120; intYear <= DateTime.Now.Year + 1; intYear++)
            {  
                 lstYear.Items.Add(Convert.ToString(intYear));
            }
            lstYear.Items.FindByValue(DateTime.Now.Year.ToString()).Selected = true;
            lstMonth.Items.Add("January");
            lstMonth.Items.Add("February");
            lstMonth.Items.Add("March");
            lstMonth.Items.Add("April");
            lstMonth.Items.Add("May");
            lstMonth.Items.Add("June");
            lstMonth.Items.Add("July");
            lstMonth.Items.Add("August");
            lstMonth.Items.Add("September");
            lstMonth.Items.Add("October");
            lstMonth.Items.Add("November");
            lstMonth.Items.Add("December");
        }
    }
    protected void calDatePicker_SelectionChanged(object sender, EventArgs e)
    {
        string date = calDatePicker.SelectedDate.ToShortDateString();
        Response.Write("<script language=javascript>");
        Response.Write("window.opener.document.forms['" + Request.QueryString.Get("FormName").ToString() + "'].elements['" + Request.QueryString.Get("ElementName").ToString() + "'].value='" + date + "';");
        Response.Write("window.close();");
        Response.Write("</script>");
    }
    protected void lstMonth_SelectedIndexChanged(object sender, EventArgs e)
    {
        calDatePicker.TodaysDate = Convert.ToDateTime(lstMonth.SelectedItem.Value + "/1/" + lstYear.SelectedItem.Value);
    }
    protected void lstYear_SelectedIndexChanged(object sender, EventArgs e)
    {
        calDatePicker.TodaysDate = Convert.ToDateTime(lstYear.SelectedItem.Value + "/1/" + lstMonth.SelectedItem.Value);
    }
}

Open in new window

0
 
rhythmluvrCommented:
ASP.NET 2.0 comes with a calendar control that works very well, have you looked into using this tool. Of course all of them require javascript as well to run correctly.

I could post my code as an example if you need it, I program in c# but for this control that shouldn't matter.
0
 
arthurh88Author Commented:
i cant read C#.  Yes I looked at the calendar control but I do not know how to "minimize it" automatically and have it automatically dump its value into a text box.  All i need to know is how to make it auto-expand, auto-dump the date into a textbox, and re-minimize
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
rhythmluvrCommented:
OK, this first post is for the calendar.aspx page that I created this has the actual calendar control on it.
<body>
    <form id="frmCalendar" runat="server">
    <div>
    <table border="0" align="center" cellpadding="0" cellspacing="0">
        <tr align="center" width="200">
            <td align="center">
            <asp:ListBox ID="lstMonth" runat="server" Rows="1" Font-Names="Verdana" Font-Size="8pt" ForeColor="#585880" EnableViewState="true" AutoPostBack="True" OnSelectedIndexChanged="lstMonth_SelectedIndexChanged">
            </asp:ListBox>
            &nbsp;&nbsp;
            <asp:ListBox ID="lstYear" runat="server" Rows="1" Font-Names="Verdana" Font-Size="8pt" ForeColor="#585880" EnableViewState="true" AutoPostBack="True" OnSelectedIndexChanged="lstYear_SelectedIndexChanged">
            </asp:ListBox>    
            </td>
        </tr>
        <tr height="5"><td></td></tr>
        <tr>
            <td>
            <asp:Calendar ID="calDatePicker" EnableViewState="false" runat="server" Width="200" Font-Names="Verdana" Font-Size="8pt" BackColor="#F1F1F1" ForeColor="#585880" TitleStyle-BackColor="#ECEDFF" 0 OnSelectionChanged="calDatePicker_SelectionChanged" TodayDayStyle-BorderWidth="1" TodayDayStyle-BackColor="#F8F7F4" TodayDayStyle-BorderColor="#585880" TodayDayStyle-ForeColor="#585880"></asp:Calendar>
            </td>
        </tr>
    </table>
    </div>
    </form>
</body>

Open in new window

0
 
rhythmluvrCommented:
And finally the code for the actual page that contains the calendar popup.
<!-- Begin javascript for calendar popup -->
<script language="Javascript">
    function GetDate(ElementName)
    { 
        child = window.open('calendar.aspx?FormName=' + document.forms[0].name + '&ElementName=' + ElementName, "PopUpCalendar", "width=275,height=185,top=200,left=200,toolbars=no,scrollbars=no,status=no,resizable=no");
    }
    function Selector(ElementName,Function)
    { 
        child = window.open('selector.aspx?Function=' + Function + '&FormName=' + document.forms[0].name + '&ElementName=' + ElementName, "PopUpSelector", "width=400,height=190,top=200,left=200,toolbars=no,scrollbars=no,status=no,resizable=no");
    }
</script>
<!-- End javascript for calendar popup -->
 
                                    <td width="125">
                                    <asp:TextBox ID="txtBirthDate" runat="server" Width="75" Font-Names="Verdana" Font-Size="10px" ForeColor="#585880" EnableViewState="false"></asp:TextBox>&nbsp;<a href="javascript:GetDate('txtBirthDate')" title='Calendar'><img src="images/calendar.gif" border="0") /></a>
                                    </td>

Open in new window

0
 
rhythmluvrCommented:
You can ignore this in the javascript, it is for a different event in my code.

    function Selector(ElementName,Function)
    {
        child = window.open('selector.aspx?Function=' + Function + '&FormName=' + document.forms[0].name + '&ElementName=' + ElementName, "PopUpSelector", "width=400,height=190,top=200,left=200,toolbars=no,scrollbars=no,status=no,resizable=no");
    }
0
 
arthurh88Author Commented:
I got it all working!  Thanks a lot!!
0
All Courses

From novice to tech pro — start learning today.