Date Date Date

Last post 05-28-2009 7:36 AM by shahed.kazi. 7 replies.

Sort Posts:

  • Date Date Date

    05-28-2009, 6:24 AM
    • Member
      7 point Member
    • kazi_azhar
    • Member since 03-04-2009, 8:23 AM
    • Ahmedabad
    • Posts 30

    Hello Friends, 

    I have Two TextBOx; TextBox1 and TextBox13.
    TextBox1 is for Birth Date and TextBox14 for Retired Date.

    My Problem is I want To display Retirement Date in TextBox14 Automaticlly by Adding 58 yeras in BirthDate At a time when user fill the Birth Date Textbox.That works fine with Code like that.

    on TextBox13_Textchanged event

    DateTime dt = DateTime.Parse(TextBox13.Text);

    TextBox14.Text = dt.AddYears(58).ToString("MM/dd/yyyy");

    But My problem is that When user Enter Wrong Date in BirthDate textbox then it will give error on page

    rather fire Validator. I already applied validator for birthdate to validate proper datetime format.

    How can I solve this matter please tel me...

     

     

    Please help me.

    A.R.Kazi
  • Re: Date Date Date

    05-28-2009, 6:34 AM
    Answer
    • Contributor
      5,952 point Contributor
    • mo meng
    • Member since 08-30-2006, 3:56 AM
    • Singapore
    • Posts 1,227

    you calendar to prevent all these kinds of error

    you can use the build in ajax calendar

    http://www.asp.net/AJAX/AjaxControlToolkit/Samples/Calendar/Calendar.aspx

     

  • Re: Date Date Date

    05-28-2009, 7:00 AM
    Answer
    • All-Star
      94,406 point All-Star
    • vinz
    • Member since 10-05-2007, 11:47 AM
    • Cebu, PH
    • Posts 13,998
    • TrustedFriends-MVPs

    kazi_azhar:
    But My problem is that When user Enter Wrong Date in BirthDate textbox then it will give error on page
     

    Based from your previous thread: http://forums.asp.net/p/1427439/3189306.aspx

    I have stated there that "when accepting inputs from the user then I would suggest to use DateTime.TryParse method instead to avoid format exceptions when converting strings value to DateTime format".

    To validate the format that was entered in the TextBox control then you can refer to this thread for a solution: http://forums.asp.net/t/1297096.aspx



    "Code,Beer and Music ~ my way of being a programmer"



  • Re: Date Date Date

    05-28-2009, 7:02 AM
    • Star
      10,552 point Star
    • getchinna_sv
    • Member since 09-10-2008, 8:29 PM
    • Hyderabad
    • Posts 1,807
    Chinna_sv...
  • Re: Date Date Date

    05-28-2009, 7:26 AM
    • Contributor
      3,230 point Contributor
    • aditya1986
    • Member since 05-04-2009, 5:04 AM
    • Posts 529

      you write this code

    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
       
          <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /> 


    in page aspx.cs file
    under button click event

    protected void Button1_Click(object sender, EventArgs e)
        {
            TextBox1.Text = DateTime.Today.ToShortDateString();
            DateTime dt = DateTime.Parse(TextBox1.Text);
            TextBox2.Text = dt.AddYears(58).ToString();
        }

    i hope it helps you


    MARK AS ANSWER if post helps
  • Re: Date Date Date

    05-28-2009, 7:30 AM
    • All-Star
      94,406 point All-Star
    • vinz
    • Member since 10-05-2007, 11:47 AM
    • Cebu, PH
    • Posts 13,998
    • TrustedFriends-MVPs

    aditya1986:
            DateTime dt = DateTime.Parse(TextBox1.Text);
     

    See my reply above why I will not recommend using DateTime.TryParse method.



    "Code,Beer and Music ~ my way of being a programmer"



  • Re: Date Date Date

    05-28-2009, 7:36 AM
    • Contributor
      3,230 point Contributor
    • aditya1986
    • Member since 05-04-2009, 5:04 AM
    • Posts 529

     Hi vinz

    if you convert TextBox1.Text  value  into  Datetime  format than it wont create any problem according to my opinion .if not we can suggest your method

    MARK AS ANSWER if post helps
  • Re: Date Date Date

    05-28-2009, 7:36 AM
    • Star
      11,983 point Star
    • shahed.kazi
    • Member since 07-08-2008, 10:15 PM
    • Sydney, Australia
    • Posts 2,360
    Why don't you use a calendar extender for the textbox.
    Shahed Kazi [SCJP]

    Read My Blog
Page 1 of 1 (8 items)