I have two textboxes on a webform (asp.net/c#) with each having the ajax calendar extender so when a user clicks in the textbox a calendar appears. The first one is date from while the second one is a date to. I want to be able to set the start date of the calendar extender of the date to, to be of the date selected in the date from.
I know this can be done by autopostbacking the textchange on the date from textbox then we can get the date from the textbox and apply to the To calendar extender, however I would prefer if there was a way we could do this without going back to the server. I am thinking javascript, we can find again look at the textchange of the textbox, like this
<asp:TextBox ID="txtFromDate" runat="server" onchange="javascript:SetToDate();"></asp:TextBox>
with the other textbox as
<asp:TextBox ID="txtToDate" runat="server"></asp:TextBox>
<act:CalendarExtender ID="calToDate" runat="server" PopupButtonID="imgPopUp" TargetControlID="txtToDate" Format="dd/MM/yyyy">
</act:CalendarExtender>
I was thinking I could have something like this in javascript
function SetToDate() {
var datestart = new Date(document.getElementById('<%=txtFromDate.ClientID %>').value);
document.getElementById('<%=calToDate.ClientID %>').StartDate = datestart;
}
However as you can see .StartDate does not belong like this, so how else can I apply the start date to calToDate via javascript.
Any help will be appreciated
I think this could be the solution
function SetToDate() {
var datestart = new Date(document.getElementById('<%=txtFromDate.ClientID %>').value);
document.getElementById('<%=calToDate.ClientID %>').value = datestart;
}
as long as the HTML generated for calToDate is an input of text type.