ajax 选项卡控件中用户控件的验证
我有一系列嵌套在 ajaxToolkit:TabContainer 中的用户控件,需要进行验证。用户控件有一个 txtFlightFrom 和一个 txtFlightTo 控件,如果 txtFlightFrom 中有数据,我需要确保 txtFlightTo 中是它们的数据(如果没有目的地机场,则无法从一个机场飞出)。我第一次尝试 asp:CompareValidator 控件,但我真正的问题是当我进入下一个选项卡时如何触发验证器。我尝试从我的 aspx 页面执行此操作,但这只会导致问题,并且在逻辑上对我来说没有意义。
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";
}
我也在 ascx.cs 中尝试了此代码的变体,但这也没有意义,因为该事件发生在 aspx.cs
有什么想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我几个月前使用的技巧是,当用户更改活动选项卡时,在客户端调用 JavaScript 函数来触发验证函数。在网上快速搜索后,我找到了这个 示例 (我不能这样做目前正在进行测试,抱歉):
The trick I used months ago was to fire the validation function on the client side calling a javascript function when the user changes the active tab. A quick search on the net lead me to this example (I can't do a test at this moment, sorry):