ajax 选项卡控件中用户控件的验证

发布于 2024-10-03 00:48:53 字数 1653 浏览 3 评论 0原文

我有一系列嵌套在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏日浅笑〃 2024-10-10 00:48:53

我几个月前使用的技巧是,当用户更改活动选项卡时,在客户端调用 JavaScript 函数来触发验证函数。在网上快速搜索后,我找到了这个 示例 (我不能这样做目前正在进行测试,抱歉):

<ajaxToolkit:TabContainer runat="server" ID="Tabs" OnClientActiveTabChanged="ActiveTabChanged">


//Javascript function  
function ActiveTabChanged(sender, e) {  
    if (Page_ClientValidate() == false) {  
        var ctrl = $find("Tabs");  
        var tabpanel = ctrl.get_tabs()[0];  
        handleTabChange = false;  
        ctrl.set_activeTab(tabpanel);  
    }  
}   

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):

<ajaxToolkit:TabContainer runat="server" ID="Tabs" OnClientActiveTabChanged="ActiveTabChanged">


//Javascript function  
function ActiveTabChanged(sender, e) {  
    if (Page_ClientValidate() == false) {  
        var ctrl = $find("Tabs");  
        var tabpanel = ctrl.get_tabs()[0];  
        handleTabChange = false;  
        ctrl.set_activeTab(tabpanel);  
    }  
}   
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文