views:

1386

answers:

4

How best to make the selected date of an ASP.NET Calendar control available to JavaScript?

Most controls are pretty simple, but the calendar requires more than just a simple document.getElementById().value.

A: 

This might help you. It uses YUI, but you can probably port some of that functionality over to another library or custom code it. It should get you started though.

http://www.codeproject.com/KB/aspnet/aspnet-yahoouicalendar.aspx

hal10001
A: 

You might find useful the MS AJAX Calendar control extender, you can get the date just by

document.getElementById('<%= DateTextBox.ClientID%>').value;

DateTextBox is an asp:TextBox control that will be extended with the AJAX calendar.

CMS
+1  A: 

When you click on a date with the calendar, ASP does a postback, you could always put the SelectedDate value of the calendar control into a hidden field on the page during the OnLoad event of the page or the SelectionChanged event of the Calendar control.

toast
A: 

I'm using Page.ClientScript.RegisterClientScriptBlock() to put a small script on the page that just declare a variable with the desired value. I was hoping for some a little less... clunky.

Joel Coehoorn