Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a problem with some ajax calendar extenders. I have similiar 2 calendars and two textboxes that are each linked to one calendar.

                        <asp:TextBox ID="txt1" runat="server"</asp:TextBox>
                    <cc1:CalendarExtender ID="calendar1" runat="server" TargetControlID="txt1"
                        Format="yyyy-MM-dd" CssClass="Calendars" Enabled="false">

When I select a date in the first calendar, I want the second calendar to place itself in the same month as the first calendar but without selecting the actual date (because doing so will make the txt2 display that date). The txt2 textbox should remain empty until a date is selected by the user in calendar2.

I have look everywhere on the internet but nothing seems to fit that situation.

can anybody help?

EDIT:

I have tried to change the date and then erase the textbox with javascript but I have a compare validator that triggers when I do so. I use the following javascript code to erase the textbox:

        function onShowingCal2(sender, e) {
        var txt2 = document.getElementById('<%= txt2.ClientID %>');
        var txt1 = document.getElementById('<%= txt1.ClientID %>');
        var cal2 = sender;
        if (txt2.value == "") {
            var dateStart = new Date();
            dateStart.setDate(txt1.value);
            cal2.set_selectedDate(dateStart );
            datechosen = false;                
        }
    }
function onTextboxChange() {
            if (!datechosen ) {
                document.getElementById('<%= txt2.ClientID %>').value = "";
            }
        }

thanks!

share|improve this question

2 Answers 2

Perhaps you can set the SelectedDate property of calendar2 but clear the text of txt2?

http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/Calendar/Calendar.aspx

There are some client event of Calendar you can use.

OnClientDateSelectionChanged    OnClientHidden    OnClientHiding

For example, you can define OnClientDateSelectionChanged="onSelectChanged()".

function onSelectChanged()
{
     alert($find('calendar1')._selectedDate);
}

So your code will become:

<cc1:CalendarExtender ID="calendar1" runat="server" TargetControlID="txt1" Format="yyyy-MM-dd" CssClass="Calendars" Enabled="false" OnClientDateSelectionChanged="onSelectChanged()">

function onSelectChanged()
{
   $find('calendar2')._selectedDate = $find('calendar1')._selectedDate;
}
share|improve this answer
    
I tried but I have a comparevalidator that is triggered when I do so, and An error message is displayed even if the textbox appears empty. –  jumojer May 30 '13 at 13:15
    
how do you do it? I meant doing it on the client through script. –  Ted May 30 '13 at 13:17
    
have a look at my edited answer –  Ted May 30 '13 at 13:21
1  
I believe better to employ get and set functions instead of direct access to _selectedDate field: $find('calendar2').set_selectedDate($find('calendar1').get_selectedDate()) –  Yuriy Rozhovetskiy May 30 '13 at 13:35
1  
And also, in onSelectChanged function you can access sender extender from first parameter: function onSelectChanged(sender, args){ alert(sender.get_selectedDate()); } –  Yuriy Rozhovetskiy May 30 '13 at 13:37
up vote 0 down vote accepted

I finnaly got something working

What I did is I took the javascript code in the question and added one very simple function:

        function EndDateChosen(e) {
        dateChosen = true;
    }

And call this like so in the calendar2 tag's property OnClientDateSelectionChanged='EndDateChosen'

that event was a pain to make work. The javascript fonction HAS to have ONLY one parameter and the fonction name in the calendar's tag HAS to be surrounded with single quotes not doubleQuotes.

thanks yall!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.