mugsey
asked on
check for valid date when textbox is visible
I have asp.net 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.Tex t); //check for valid date here
}
else
{
customer.DateRaised = DateTime.Now;
}
if (checkbox.Checked)
{
customer.DateRaised = DateTime.Parse(txtDate.Tex
}
else
{
customer.DateRaised = DateTime.Now;
}
best way you can use any date control along with textbox
ASKER
Thanks but I need to use microsoft controls within visual studio
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
hey,
checkbox should be enabled with Autopostback property,,,see below..for the definition
<asp:CheckBox ID="CheckBox1" runat="server"
oncheckedchanged="CheckBox 1_CheckedC hanged" Checked="false" AutoPostBack="true" />
In the Page load event
PageLoad()
{
txtDate.Visible =false; //make your textbox false
}
In the CheckBox1_checkedChanged()
{
if (CheckBox1.Checked)
TextBox1.Visible = true;
else
TextBox1.Visible= false;
}
In the TextBox1_TextChanged event()
{
customer.DateRaised = DateTime.Parse(TextBox1.Te xt);
}
checkbox should be enabled with Autopostback property,,,see below..for the definition
<asp:CheckBox ID="CheckBox1" runat="server"
oncheckedchanged="CheckBox
In the Page load event
PageLoad()
{
txtDate.Visible =false; //make your textbox false
}
In the CheckBox1_checkedChanged()
{
if (CheckBox1.Checked)
TextBox1.Visible = true;
else
TextBox1.Visible= false;
}
In the TextBox1_TextChanged event()
{
customer.DateRaised = DateTime.Parse(TextBox1.Te
}
You can try like this
If CheckBox1.Checked = True Then
TextBox1.Visible = True
Else
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
If CheckBox1.Checked = True Then
TextBox1.Visible = True
Else
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