.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Validate ASP.net calendar date selected with Javascript?

Posted By:      Posted Date: September 24, 2010    Points: 0   Category :ASP.Net

Is there any way I can use javascript to make sure the user has selected a date from my asp.net calendar? I have the calendar under an update panel:

                        <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                                <asp:Calendar ID="Calendar1" runat="server" BackColor="#FFFFCC" BorderColor="Maroon"
                                    BorderWidth="1px" CssClass="calendar" Font-Names="Verdana" Font-Size="9pt" ForeColor="Black"
                                    Height="200px" Width="305px" DayNameFormat="Shortest" ShowGridLines="False">
                                    <SelectedDayStyle BackColor="maroon" BorderColor="Black" BorderWidth="1px" Font-Bold="true" Font-Size="11pt" />
                                    <SelectorStyle BackColor="#FFCC66" />
                                    <TodayDayStyle Font-Bold="true" Font-Size="16pt"/>
                                    <OtherMonthDayStyle ForeColor="#CC9966" />

View Complete Post

More Related Resource Links

Validate (Javascript) if input date is within this range...


I'd like to validate if the inputed date is within this range:

3 weeks before today's date to 3 weeks after today's date 

The following Javascript code checks if the date is within either today's date or 2 weeks before:

var dateSystem = (dateToday.getMonth() + 1) + dtCh + dateToday.getDate() + dtCh + dateToday.getFullYear();
            var prev = new Date();
            //past date 14 dates before today
            prev.setDate(prev.getDate() - 14);
            var pastDate = (prev.getMonth() + 1) + dtCh + (prev.getDate()) + dtCh + prev.getFullYear();
            var time1 = new Date(dateSystem).getTime();
            dtStr = month + dtCh + day + dtCh + year;
            var dateuser = new Date(dtStr);
            var time2 = dateuser.getTime();
            if (time1 - time2 <= 1209600000 && time2 <= time1) {
                return true;
            } else {
                alert("Vaccines/Services date must be within this date range: " + pastDate + " to " + dateSystem);
                return false
            return true


I'm not sure how to modify. I actually got the code above from these forums.

Help is much appreciated!

show selected date in calendar


Hi all,

I've got this terrible brain freeze today ;-)

I have an asp:Calendar (not ajax). When I set the selectedDate from codebehind to a date in another month, I'd want the new selected date to show (that is, show the calendar "page" with the new month. How do I do this?

calFromDate.SelectedDate = myDate 'works fine

calFromDate.ShowSelectedDate's Month 'pseudocode


The calendar resides in an updatepanel for speed purposes, but I don't think that has anything to do with anything...


Thanks a lot!


reportviewer date parameter and calendar.. not working and javascript errors??



Hi, I've got this ssrs 2005 report that works great passing a few
security related parameters from asp.net codebehind. However, there
are two date related parameters that won't be coming from my web form,
but rather from the report form itself. When I test the report's date
parameters from visual studio it work fine, but when I attempt the
same report from a reportviewer no matter what input I place on the
report's date fields or even if I select the date picker, the report
simply resets to default and reloads. And actually the date picker
from the reportviewer does not not even pop up.


Here's my aspx code:

<%@ Page Language="VB" AutoEventWireup="false"
Inherits="_ReportViewer" MasterPageFile="~/Main/MasterPage.master"
    CodeFile="~/Reports/CashSales.aspx.vb"  Title="Cash Sales" %>

<%@ Register Assembly="Microsoft.ReportViewer.WebForms,
Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
    Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>

<asp:Content ID="Content1" ContentPlaceHolderID="Content1"

Problem in setting calendar selected date


I am using the fallowing code to set the selected date of calendar control to one day previous of the current date, but still the calendar is showing the current date as the selected date.

Calendar1.SelectedDate =


can anyone help me regarding this issue.

change calendar date backColor base on data from db


I want to  change calendar date backColor base on data from db,  I only have vistual 2003 !

on mean time I have

<asp:DataGrid id="DataGrid1" style="Z-INDEX: 102; LEFT: 23px; POSITION: absolute; TOP: 271px"
		    runat="server" Font-Size="XX-Small" Font-Names="Verdana" AutoGenerateColumns="False" Visible="False">
           <asp:BoundColumn DataField="subject" HeaderText="Title"></asp:BoundColumn>
           <asp:BoundColumn DataField="posttimestart" HeaderText="Post date"></asp:BoundColumn>


Sub DayRender(ByVal source As Object, ByVal e As DayRenderEventArgs)
        Dim i As Integer
        For i = 0 To DataGrid1.Items.Count - 1
            If (DataGrid1.Items(i).Cells(1).Text = e.Day.Date) Then
                e.Cell.BackColor = Color.DarkOrange

            End If

    End Sub

when I click the day wich have data in db it change  color , but I want the page load it change color !

Thank you!

Calendar control and date


I have a calendar control , text box and a button . The calendar is invisible in the page load event. When I click on the button,It becomes visible. On selection of a date it becomes the value of the Text Box.
Having said that, my issue is that when this calendar becomes visible, it ruins the arrrangement of the controls on the  page. As I have other controls on the page they  comepletely get displaced. Is there a way to overlap this calendar over the other controls.
I had seen a control that was  some time ago and it was on the client side(probably using javascript or a third party control ) and It wud overlap the other controls and once a value was selected it became invisible.

Submtting Calendar items with variable date information via InfoPath 2007 form



I've seen several posts regarding submitting to a list using and InfoPath form which I am successfully able to do in limited form. (only passing a basic date value) My environment: MOSS 2007 Enterprise w/SP2, InfoPath 2007, SPD 2007.

I'm basically trying to recreate a calendar form with the same data elements (and some additional ones for a specific business requirement) as the standard calendar newform.aspx form. (start time, end time broken down by date, hour, minute and All day event)

I need the form users to be able to select the date and if it is not an All day event...be able to select the hours and minutes just like on the newform.aspx. (date picker control for date and drop downs for hour and minute selection)

On submit I then need to create the list item with the appropriate data passed via a workflow.

My Start Time has a validation rule to not allow dates prior to the current date (and it can't blank) The End Time has a validation rule to not allow dates prior to what is specified as the Start Time value. (Also can't be blank) When I attempt to include conditonal formatting to hide the hour and minute drop downs if 'All Day Event' is selected I get errors stating the fields can't be blank.

I also can't figure out how to pass the entire date/time values or the All Day Event to the list withou

How to add days in date using javascript


Hi following is the javascript code which i used for adding days to date

my date is 25/08/2010  and i want to add 8 days to this date  the answer should be 03/09/2010. how it is possible. i tried following code but showing error.



<script type="text/javascript" language="javascript">

function check()
var myDate = new Date();
var vFormat="MM/dd/yyyy";
var vDay                = addZero(myDate.getDate()); 
var vMonth            = addZero(myDate.getMonth()+1); 
var vYearLong         = addZero(myDate.getFullYear()); 
var vYearShort        = addZero(myDate.getFullYear().toString().substring(3,4)); 
var vYear             = (vFormat.indexOf("yyyy")>-1?vYearLong:vYearShort) 
var vHour             = addZero(myDate.getHours()); 
var vMinute           = addZero(myDate.getMinutes()); 
var vSecond           = addZero(myDate.getSeconds()); 
var myDateString       = vFormat.replace(/dd/g, vDay).replace(/MM/g, vMonth).replace(/y{1,4}/g, vYear) 
myDateString           = myDateString.replace(/hh/g, vHour).replace(/mm/g, vMinute).replace(/ss/g, vSecond) 

function addZero(vNumber){ 
    return ((vNumber < 10) ? "0" : "") + vNumber 


validate the selection of atleast one checkbox in the gridview using javascript


 i have a gridview with a checkbox in the templatefield as given  below,

<asp:GridView runat="server" ID="gvAsgnHw"  AutoGenerateColumns="False"   >
        <asp:CheckBox id="cbAsgnHwGrid"   runat="server" /> </ItemTemplate></asp:TemplateField>

         <asp:BoundField DataField="Resource_id" HeaderText="Resource ID"/>
        <asp:BoundField DataField="Resource_name" HeaderText="Hardware Name" />

I want to check the selection of atleast one checkbox on a button click using javascript.
pls help

Javascript code to copy selected dropdown item to clipboard

Does anyone know how I can do this to get the text onto the clipboard?  <input id="Copy" type="button" value="Copy Url" runat="server" onclick="copy();" style="vertical-align: top;" visible="false"/><script type="text/javascript"> function copy() { var sel = document.getElementById("DropDownList1"); var text = sel.options[sel.selectedIndex].value; ??? } </script> </body>  

Sort WSS 3.0 Calendar by Start Date

I have read a few posts about people not being able to sort by start date on the calendar.  Was wondering if anyone has this figured out to sort by start date correctly with re-occuring appointments?  I have a code snippet from another post but do not know how to format it correctly as I am a new sharepoint user.  If someone can help with that that is also appreciated.  Thanks.  Code Below:  I basically have no idea to find the info requested below <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <script> //today's date var today = new Date(); //get the Date var myDate = today.getDate(); //get the Month var myMonth = today.getMonth()+1; //get the Year var myYear=today.getYear(); //put date into a mm/dd/yyyy format var myDate = myMonth + "/" + myDate + "/" + myYear; //If this is on a webparts page, get the WP div id.  If it's on a list page, you don't need the webzone div ID. //Get the table and table class (usually it's .listviewtable, but if you've customized a webpart, sometimes it's .ms-summarycustombody.  //I used Todd Bleeker's "Style Under Cursor WebPart" to find the CSS class. $(function(){ $('div#WebPartWPQ3 table.ms-listviewtable tr:not(:contains("' + myDate 

Ajax Calendar Extender Question (about disable pass date)

HiI am wondering if it has anyway to disable the past day on the Ajax Calendar Control, previously, when we use CalendarExtender, we need to put a asp:Calendar and a textbox. we can use FindControl to find the calendar control and disable the past days.I am wondering is there anyway  could do the same stuff?Another question is how could I read the user selected date to the Date variable?Do i need to convert the date from the TargetControl ? E.g. Convert.ToDateTime(txt_DATE.text) ?Please let me know if you want me to explain more.Many thanksChi 

Calendar Date Picker Restriction

Is there a way to restrict the user to selecting only the first day of a month from the Date Picker calendar? The database list the yearmonth column as datetime and the entries are 01/01/2010, 02/01/2010, 03/01/2010. . . to represent the month. So I need to be able to provide the calendar in the parameter panel but only let the user select the first day of a month. If I can't do this is there some way of providing an error message when/if they select another day of the month that would instruct them to select the first day of the month? Any help is greatly appreciated.

Trap Selected Index change event of listbox using Javascript.

Hi All, This is reagarding listbox selection. I have a list box with multi select option. I want to trap the selected index change event of Listbox through javascript. Item of list box can be selected using Click of mouse and also the keyboard up down key with shift. I tried onclick event to bind the javascript function. It works fine if I select by mouse, but it doesen't work for up/down key of keyboard. Thanks, Naveen

validate date/time span and alow only time input

Hi, I have 2 small questions: 1. How can I  make a filed for input only time without date? 2. I need to make a date/time validation in form like: if(time between begin_date_field  and end_date_field) is not in intersection (time between begin_date_field  and end_date_field) of any item in list) Can I make this validation only using VisualStudio2010 or is there a simpler way? ( I need this for small list for managing reservations of conference rooms )

Getting Selected Item in radiobuttonlist on content page using javascript

I am trying get the selected value from a radiobuttonlist on a content page using javascript. Here is my initial code, which does not recognize the control. The js is located in a separate file and there is a link on the content page pointing to the js file. Thanks, function GetRadioButtonValue() { var radio = document.getElementsByName('<%=rblPayType.ClientID%>'); for (var j = 0; j < radio.length; j++) { if (radio[4].checked) { alert(); return; } else { return; } } }    

Javascript FromDate to Date Validation Help!

Hi,I want to check fromdate and todate in dd/mm/yyyy.The code below mentioned works perfect for single textbox(fromdate) ,but when tried to do for todate(textbox) it doesnot work properly.From Date Should not be greater than ToDate.Please Help.Below is the code:<html><head><title>Date Example</title><script type="text/javascript">    function isValidDate(sText) {        var reDate = /(?:0[1-9]|[12][0-9]|3[01])\/(?:0[1-9]|1[0-2])\/(?:19|20\d{2})/;        return reDate.test(sText);    }    function validate() {        var oInput1 = document.getElementById("txt1");        if (isValidDate(oInput1.value)) {            alert("Valid");        } else {            alert("Invalid!");        }    }</script></head><body>    <P>Date: <input type="
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend