How to change txt2.text when the txt1's date of AJAX CalendarExtender changes?

Last post 07-02-2009 8:39 PM by wooper. 11 replies.

Sort Posts:

  • How to change txt2.text when the txt1's date of AJAX CalendarExtender changes?

    02-10-2009, 5:10 AM
    • Member
      239 point Member
    • MinimalTech
    • Member since 01-19-2009, 12:22 PM
    • Greece
    • Posts 174

     Hi!

    I  have two text boxes inside my aspx page: a) the "txt1" and b) the "txt2".

    Both text boxes has CalendarExtender controls attached: a) the txt1 has the "CalendarExtender1" and b) the txt2 has the"CalendarExtender2".

    All i want, is this:

    Using client-side script (or other method without postbacks), i want when the user chooses a date from CalendarExtender1,

    the same date plus a day front to go to the txt2.

    For example:

    If the user choose 03/28/2009 in the CalendarExtender1, i want the value of the txt2 to be the 03/29/2009....

    Also, if the month reaches the end, i want the txt2 to take the new moth. For example:

    If the user choose 03/31/2009 in the CalendarExtender1, i want the value of the txt2 to be the 04/01/2009....

    That behavior i want to exists only to the CalendarExtender1 like i describe it. I don't want the user to be able to do this

    with CalendarExtender2 (the CalendarExtender2 has the default behavior)...

     

    How can i accomplish that? Thank you very much!

    Please, mark this post as "Answer" if it helped you solve your problem.

    MinimalTech.
  • Re: How to change txt2.text when the txt1's date of AJAX CalendarExtender changes?

    02-10-2009, 5:55 AM
    • Participant
      1,635 point Participant
    • sangam100
    • Member since 07-22-2008, 10:44 AM
    • Kathmandu,Nepal
    • Posts 313

    Hi MinimalTech ,

    Put the controls in an updatepanel, and in the textchanged event of first textbox, read it's text, convert to datetime and add 1 day in this and display in second textbox. You should enable postback in the first textbox.

    Hope this helps. Please feel free to ask if any problem persists or if any help is required. Thanks.

    Lets always remember to mark the post that helps us as "Mark as Answer".
    Very useful visual studio shortcuts and more tips and tricks
    5 Different ways to open new window in asp.net
  • Re: How to change txt2.text when the txt1's date of AJAX CalendarExtender changes?

    02-10-2009, 6:08 AM
    • Member
      239 point Member
    • MinimalTech
    • Member since 01-19-2009, 12:22 PM
    • Greece
    • Posts 174

    Thank you very much  sangam100!

    Your solution looks fine (also i was thinking something similar to do) but, as i said to my 1st post:

    MinimalTech:

    ...Using client-side script (or other method without postbacks), i want when the user chooses a date from CalendarExtender1,

    the same date plus a day front to go to the txt2...

     

    i'm tryiing to  avoid the posts back even if the postbacks is from the update panel..

    Do you know some way to do this via javascript or AJAX?

    Please, mark this post as "Answer" if it helped you solve your problem.

    MinimalTech.
  • Re: How to change txt2.text when the txt1's date of AJAX CalendarExtender changes?

    02-10-2009, 6:14 AM

     Please download this control and place two controls inside an update pannel.

    download control for your framework:

    http://www.eworldui.net/Download.aspx

    something liek this.

    <asp:UpdatePanel id="UpdatePanel1" runat="server">
            <contenttemplate>
    <cc2:CalendarPopup id="CalendarPopup1" runat="server" Width="71px" OnDateChanged="CalendarPopup1_DateChanged" AutoPostBack="True"></cc2:CalendarPopup> <cc2:CalendarPopup id="CalendarPopup2" runat="server" Width="71px"></cc2:CalendarPopup>
    </contenttemplate>
        </asp:UpdatePanel>

    Code behind:

     protected void CalendarPopup1_DateChanged(object sender, EventArgs e)
        {
            CalendarPopup2.SelectedDate = CalendarPopup1.SelectedDate.AddDays(1);
        }

    Thanks and Regards
    Nimesh Prabhakar


    Mark this post as "ANSWER", if it helped you..
  • Re: How to change txt2.text when the txt1's date of AJAX CalendarExtender changes?

    02-10-2009, 6:50 AM
    • Member
      239 point Member
    • MinimalTech
    • Member since 01-19-2009, 12:22 PM
    • Greece
    • Posts 174

     Thank you nimeshprabhakar, but even this solution uses the update panel...

    As i said, i do not want any postbacks... So i do not want any update panel...

    I want some pure JavaScript solution....

    Please, mark this post as "Answer" if it helped you solve your problem.

    MinimalTech.
  • Any solution algorithm for Date Forwarding?

    02-11-2009, 5:03 AM
    • Member
      239 point Member
    • MinimalTech
    • Member since 01-19-2009, 12:22 PM
    • Greece
    • Posts 174

    Hey guys!

    Did anyone found a solution algorithm to forward the dates correctly?

    Thanks!

     

    Please, mark this post as "Answer" if it helped you solve your problem.

    MinimalTech.
  • Re: Any solution algorithm for Date Forwarding?

    02-11-2009, 8:23 AM
    Answer
    • Participant
      943 point Participant
    • kinjalin
    • Member since 11-07-2008, 7:46 AM
    • Mumbai
    • Posts 166

    here you have to add it in Javascript

    <cc1:CalendarExtender ID="ClExFromDt" 
    runat="server"
    TargetControlID="TxtFromDate"
    PopupButtonID="BtnFromCal"
    Format="dd/MM/yyyy"
    OnClientDateSelectionChanged="AddDate"
    CssClass="calExt_Theme1">
    </cc1:CalendarExtender>

    Here on OnBlur, write a Javascript function addDate

    on Page_Load write the line " Text1.Attributes.Add("onblur", "javascript:addDate();")

    & in Javascript Fetch the Value using document.getElementByID("TextBox1").value

    add it using below Javascript & bit of ur Logic

    //create the date
    var myDate = new Date();

    //add a day to the date
    myDate.setDate(myDate.getDate() + 1);

    //add a week
    myDate.setDate(myDate.getDate() + 7);

     after  adding Show it in ur TextBox2

    $get(TextBox2).value = myDate

    Thats it.

    Regards
    KINJAL

    "Mark the post as answered if it solves your Query"
  • Re: Any solution algorithm for Date Forwarding?

    02-11-2009, 8:57 AM
    Answer
    • Participant
      1,635 point Participant
    • sangam100
    • Member since 07-22-2008, 10:44 AM
    • Kathmandu,Nepal
    • Posts 313

    Hi MinimalTech ,

    Here goes the prototype, which is close to what kinjalin posted:

    Add this script in the design page:

    1    <script>
    2    function addDays() {
    3        dateParts = document.getElementById('txtDate1').value.split('/');
    4        year  =  dateParts[2];
    5        month = parseInt(dateParts[0])-1;
    6        day   = parseInt(dateParts[1]) + 1;
    7        
    8        newDate = new Date ( year, month, day );
    9        year  = newDate.getYear();
    10       month = newDate.getMonth()+1;
    11       day   = newDate.getDate();
    12       formattedDate = month + '/' + day + '/' + year;
    13   
    14       document.getElementById('txtDate2').value=formattedDate;
    15   }
    16   
    Now in the design page:

    Date1:

    <asp:TextBox ID="txtDate1" runat="server"></asp:TextBox>&nbsp; Date2 (One day forward):

    <asp:TextBox ID="txtDate2" runat="server"></asp:TextBox>

    <cc1:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="txtDate1" PopupButtonID="txtDate1">

    </cc1:CalendarExtender>

     

    In the code behind:

     

    txtDate1.Attributes.Add("onchange", "addDays();");

     

    Now this works.

     

    Hope this helps. Please feel free to ask if any problem persists or if any help is required. Thanks.

    Lets always remember to mark the post that helps us as "Mark as Answer".
    Very useful visual studio shortcuts and more tips and tricks
    5 Different ways to open new window in asp.net
  • Re: Any solution algorithm for Date Forwarding?

    02-11-2009, 1:51 PM
    • Member
      239 point Member
    • MinimalTech
    • Member since 01-19-2009, 12:22 PM
    • Greece
    • Posts 174

     Thank you kinjalin and sangam100!!

    Your solutions are great!

    Please, mark this post as "Answer" if it helped you solve your problem.

    MinimalTech.
  • Re: Any solution algorithm for Date Forwarding?

    07-02-2009, 5:49 PM
    • Member
      2 point Member
    • Playbill
    • Member since 07-02-2009, 9:44 PM
    • Posts 1

    I'm on a similar scenario but my 2nd textbox's default value is 01/01/1900.  The Javascript does change the value of the 2nd textbox but when I click on the image button to show the calendar, the value of the calendar is still at 01/01/1900 - not the new value that comes from the Javascript.  Any idea how to sync the calendar extender value?  Thanks!

  • Re: How to change txt2.text when the txt1's date of AJAX CalendarExtender changes?

    07-02-2009, 8:28 PM
    • Member
      10 point Member
    • wooper
    • Member since 10-20-2008, 7:08 PM
    • Posts 41

     Hi, the solution of this problem was great, but i have a question, how can i prevent to erase de value in the textbox after a postback, because when i select a date and i use a postback it dissapears, how can i prevent that

  • Re: How to change txt2.text when the txt1's date of AJAX CalendarExtender changes?

    07-02-2009, 8:39 PM
    • Member
      10 point Member
    • wooper
    • Member since 10-20-2008, 7:08 PM
    • Posts 41

    Ok i just realesed that this happens only when the textbox is read only = true, so if i put it false and use an attribute it works just fine, thanks 

Page 1 of 1 (12 items)