views:

52

answers:

2

I have a textbox, a imagebutton and a calendar control inside a user control to pick the date from calendar and set the selected date inside textbox. All work well except the validation. I tried to validate the textbox's value to be a valid date. If it is not valid date, I want to reselect date from calendar. but looks like if valication failed, I could not reselect date if I did not put a correct date inside textbox. Basically validation requires me to fix invalid date first before I try to select a valid date. but I want to reselect when validation failed.













   protected void Calendar1_SelectionChanged(object sender, EventArgs e)
    {    // Set Date Time value into the TextBox control    
        TextBox1.Text = Calendar1.SelectedDate.ToString("MM/dd/yyyy");        
        // Hide the Calendar control after selecting the date    
        Calendar1.Visible = false;    
    }
    protected void ImgButton1_Click(object sender, EventArgs e)
    {            
         Calendar1.Visible = !Calendar1.Visible;        
    }
A: 

Acutally I figured this one out. By adding validation group to only textbox and required validators, not the calendar control. It will allow me to reselect from calendar control even if textbox value is not valid.

Cindy
But here I have another question. Everything is working except that if the textbox value is not valid and I can see the error message. But if I clicked the submit button outside this user control, it wont submit the form But MY Error message disappeared. Ideally I want my validation error message stays even I click the submit button.
Cindy
A: 

This is solved. Just by setting different validation group name, everything is working fine.

Cindy