I have a series of usercontrols nested in an ajaxToolkit:TabContainer that need to be validated. The user control has a txtFlightFrom and a txtFlightTo control and I need to make sure that is their is data in the txtFlightTo if there is data in txtFlightFrom (you can't fly out of one airport without a destination airport). I'm trying the asp:CompareValidator control for the first time but my real issue is how I triggering the validator when I proceed to the next tab. I tried doing it from my aspx page but that just causes problems and logically doesn't make sense to me.
ascx:
<asp:CompareValidator ID="CompareValidator1" runat="server" ControlToValidate="txtFlightFrom" ControlToCompare="txtFlightTo" Type="String" ErrorMessage="CompareValidator" />
<asp:Label ID="lblCompareTOFROM" runat="server" />
<asp:TextBox ID="txtFlightFrom" runat="server" />
<asp:TextBox ID="txtFlightTo" runat="server" />
aspx:
<ajaxToolkit:TabContainer ID="TabContainer1" runat="server" AutoPostBack="true" OnActiveTabChanged="TabContainer1_ActiveTabChanged">
<ajaxToolkit:TabPanel ID="TabPanel1" runat="server" HeaderText="Flights">
<ContentTemplate>
<ucFlight:FlightControl id="FlightControl1" Runat="server" />
<ucFlight:FlightControl id="FlightControl2" Runat="server" />
</ContentTemplate>
</ajaxToolkit:TabPanel>
<ajaxToolkit:TabPanel ID="TabPanel2" runat="server" HeaderText="Cars">
stuff
</ajaxToolkit:TabPanel>
ascx.cs
public string ValidateToFrom
{
get { return lblCompareTOFROM.Text; }
set { lblCompareTOFROM.Text = value; }
}
aspx.cs
if (Page.IsValid)
{
FlightControl1.ValidateToFrom = "Not Valid";
}
I've also tried variations of this code in the ascx.cs but that also doesn't make sense because the event is happening in the aspx.cs
Any thoughts?