check for valid date when textbox is visible

I have page with checkbox and textbox, if checkbox is checked then textbox is made visible and I then need to check for a valid date.  However if checkbox is not checked then I hide textbox and do not need to check for a valid date.  How can I do this?  This is my code.......

if (checkbox.Checked)
                customer.DateRaised = DateTime.Parse(txtDate.Text);  //check for valid date here
                customer.DateRaised = DateTime.Now;
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Pratima PharandeCommented:
best way you can use any date control along with textbox
Pratima PharandeCommented:
mugseyAuthor Commented:
Thanks but I need to use microsoft controls within visual studio
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

I can't quite figure out what exactly you want but your code should look like this

if checkbox.checked then
      'show textbox and check for date
       textbox.visible = true
       check for date here
     ' just hide textbox
      textbox.visible = false
end if

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
checkbox should be enabled with Autopostback property,,,see below..for the definition

<asp:CheckBox ID="CheckBox1" runat="server"
            oncheckedchanged="CheckBox1_CheckedChanged" Checked="false" AutoPostBack="true" />

In the Page load event
  txtDate.Visible =false; //make your textbox false

In the CheckBox1_checkedChanged()
 if (CheckBox1.Checked)
            TextBox1.Visible = true;          
            TextBox1.Visible= false;

In the TextBox1_TextChanged event()
     customer.DateRaised = DateTime.Parse(TextBox1.Text);  
Pratima PharandeCommented:
You can try like this

  If CheckBox1.Checked = True Then
            TextBox1.Visible = True
            TextBox1.Visible = False
            TextBox1.Text = DateTime.Now
        End If

Add regular expression validator with date validation regular expression
when checkbox not selected just set valid date as now
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.