Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7902607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:32:41+00:00 2026-06-03T09:32:41+00:00

I have a TextBox and Extender AjaxCalander on it. Its working fine showing only

  • 0

I have a TextBox and Extender AjaxCalander on it. Its working fine showing only month and year in TextBox when a date is selected. My code is below

 <asp:TextBox ID="txtCardExpiry" runat="server" Width="200px" /><span> MMYY</span>
 <ajaxToolkit:CalendarExtender runat="server" Format="MMyy" TargetControlID="txtCardExpiry" />

I want to validate if credit card is not expired

Now how I compare txtCardExpiry.Text with todays month and year only

right now im using

 int dtNowYear = Convert.ToInt16(DateTime.Now.Year.ToString().Substring(2, 2));
            int dtNowMonth = Convert.ToInt16(DateTime.Now.Month.ToString());
            int dtExpYear = Convert.ToInt16(txtCardExpiry.Text.Substring(2, 2));
            int dtExpMonth = Convert.ToInt16(txtCardExpiry.Text.Substring(0, 2));

            if (dtNowYear == dtExpYear && dtNowMonth > dtExpMonth)
            {
                lblMessage.Attributes.Add("class", "lblMessageError");
                lblMessage.Text =
                    "Credit Card expiry month and year cannot be less than todays month and year or your Credit Card has expired";
                return false;
            }
                 else if (dtNowYear > dtExpYear) 
                {
                    if (dtNowMonth > dtExpMonth)
                    {
                        lblMessage.Attributes.Add("class", "lblMessageError");
                        lblMessage.Text =
                            "Credit Card expiry month and year cannot be less than todays month and year or your Credit Card has expired";
                        return false;
                    }
                    return false;
                } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T09:32:43+00:00Added an answer on June 3, 2026 at 9:32 am

    Try

    txtCardExpiry.Text.Compare(DateTime.Now.ToString("MMyyyy"))
    

    Custom Date and Time Format Strings
    Must say, MSDN is very helpful.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a textbox for date. It has calender control extender to select date.
I have a textbox and a calendar extender, here's the code in page Default.aspx:
I have an Ajax autocomplete extender, and it is working fine. However, I want
i have a textbox associated with a calendar extender and a masked edit extender
I have a check box, RequiredFieldValidator and textbox that have editmask extender I want
I have update panel that content check box, textbox, 3 DropDownList with CascadingDropDown extender.
I have a textbox.In its onclick iam calling a javascript fn to call calendar.Texbox
only numbers must be in that textbox that entries have to be in 100
I have a Ajax auto complete extender attached to TextBox control. When the user
Morning - I'm having a little problem. I have an autocomplete extender textbox where

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.