TabContainer 问题

发布于 2024-09-24 20:14:16 字数 2750 浏览 3 评论 0原文

AJAX 工具包中的 TabContainer 有一个奇怪的问题。

我们对作为 ASP.net 控件构建的客户记录系统有多个视图。这些控件使用 UpdatePanel 异步加载数据。我们使用 jQuery 和 jquery.ui 将这些控件放置在单个页面上的单独选项卡中。

一切都很顺利。

最近,我有点厌倦了 jQuery 选项卡的 hackish 方法,并决定移植所有内容以使用 TabContainer。我希望能够将选项卡作为对象进行控制。

乍一看,一切都很完美。我只是将控件放入 TabContainer 中的选项卡中,一切看起来都很棒。但是,由于某种原因,数据绑定控件正在丢失数据。

例如,当我切换页面时,网格视图消失。具有 OnTextChanged 事件的下拉控件在回发时会丢失其数据绑定值列表。

关于 TabContainer 的一些事情 ->自定义控制->更新面板->使用数据绑定层次结构的控件使其变得不正常,并且调试器没有提供任何线索。似乎控制状态没有被存储。

我对控制状态了解不够,不知道要寻找什么。

有什么想法吗?这是 TabContainer 的标记:

<asp:TabContainer ID="tcBanner" runat="server" ActiveTabIndex="0" Width="100%" 
    EnableViewState="False" ScrollBars="Vertical">
    <asp:TabPanel runat="server" HeaderText="Comments" ID="tbComments">
        <ContentTemplate>
            <luBannerControl:Comments ID="commentsTabContent" runat="server" />
        </ContentTemplate>
    </asp:TabPanel>        
    <asp:TabPanel runat="server" HeaderText="General" ID="tbContact">
        <ContentTemplate>
            <luBannerControl:Contact ID="contactTabContent" runat="server" />
        </ContentTemplate>
    </asp:TabPanel>
</asp:TabContainer>

这是其中一个控件的标记:

<asp:UpdatePanel ID="pnlComments" UpdateMode="Conditional" runat="server">
    <ContentTemplate>
        <asp:GridView ID="CommentsGridView" AllowPaging="true" PageSize="20" DataSourceID="BannerSqlDataSource" runat="server" AutoGenerateColumns="False" GridLines="None" CssClass="CommentGrid" HeaderStyle-CssClass="CommentGridHeader" RowStyle-CssClass="CommentRowsEven" AlternatingRowStyle-CssClass="CommentRowsOdd">
            <Columns>
                <asp:BoundField DataField="SPRCMNT_TEXT" HeaderText="Comment" SortExpression="SPRCMNT_TEXT" />
                <asp:BoundField DataField="SPRCMNT_DATE" HeaderText="Created" SortExpression="SPRCMNT_DATE" DataFormatString="{0:M/dd/yyyy}" />
                <asp:BoundField DataField="SPRCMNT_CMTT_CODE" HeaderText="Type" SortExpression="SPRCMNT_CMTT_CODE" />
                <asp:BoundField DataField="SPRCMNT_CTYP_CODE" HeaderText="Source" SortExpression="SPRCMNT_CTYP_CODE" />
                <asp:BoundField DataField="sprcmnt_user_id" HeaderText="User" SortExpression="sprcmnt_user_id" />
            </Columns>
        </asp:GridView>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="txtSearch" EventName="TextChanged" />
        <asp:AsyncPostBackTrigger ControlID="btnClearFilter" EventName="Click" />
    </Triggers>
</asp:UpdatePanel>

Having a strange issue with the TabContainer in the AJAX Toolkit.

We have several views into a customer record system that we have built as ASP.net controls. These controls use UpdatePanels to load data asynchronously. We use jQuery and jquery.ui to place these controls in separate tabs on a single page.

Which all works swimmingly.

Lately, I've gotten a little tired of the jQuery tab hackish approach and decided to port everything to use the TabContainer. I want to be able to control the tabs as objects.

At first glance, everything works perfectly. I just slapped the controls into tabs in a TabContainer and everything looked great. However, for some reason, databound controls are losing their data.

For instance, grid views vanish when I switch pages. A drop down control with an OnTextChanged event, loses its databound list of values upon post back.

Something about the TabContainer -> Custom Control -> UpdatePanel -> Control that uses data binding heirarchy is throwing it out of whack and the debugger isn't shedding any light. It seems like control state isn't being stored.

I don't really know enough about control state to know what to look for.

Any ideas? Here is the markup for the TabContainer:

<asp:TabContainer ID="tcBanner" runat="server" ActiveTabIndex="0" Width="100%" 
    EnableViewState="False" ScrollBars="Vertical">
    <asp:TabPanel runat="server" HeaderText="Comments" ID="tbComments">
        <ContentTemplate>
            <luBannerControl:Comments ID="commentsTabContent" runat="server" />
        </ContentTemplate>
    </asp:TabPanel>        
    <asp:TabPanel runat="server" HeaderText="General" ID="tbContact">
        <ContentTemplate>
            <luBannerControl:Contact ID="contactTabContent" runat="server" />
        </ContentTemplate>
    </asp:TabPanel>
</asp:TabContainer>

Here is the markup for one of the controls:

<asp:UpdatePanel ID="pnlComments" UpdateMode="Conditional" runat="server">
    <ContentTemplate>
        <asp:GridView ID="CommentsGridView" AllowPaging="true" PageSize="20" DataSourceID="BannerSqlDataSource" runat="server" AutoGenerateColumns="False" GridLines="None" CssClass="CommentGrid" HeaderStyle-CssClass="CommentGridHeader" RowStyle-CssClass="CommentRowsEven" AlternatingRowStyle-CssClass="CommentRowsOdd">
            <Columns>
                <asp:BoundField DataField="SPRCMNT_TEXT" HeaderText="Comment" SortExpression="SPRCMNT_TEXT" />
                <asp:BoundField DataField="SPRCMNT_DATE" HeaderText="Created" SortExpression="SPRCMNT_DATE" DataFormatString="{0:M/dd/yyyy}" />
                <asp:BoundField DataField="SPRCMNT_CMTT_CODE" HeaderText="Type" SortExpression="SPRCMNT_CMTT_CODE" />
                <asp:BoundField DataField="SPRCMNT_CTYP_CODE" HeaderText="Source" SortExpression="SPRCMNT_CTYP_CODE" />
                <asp:BoundField DataField="sprcmnt_user_id" HeaderText="User" SortExpression="sprcmnt_user_id" />
            </Columns>
        </asp:GridView>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="txtSearch" EventName="TextChanged" />
        <asp:AsyncPostBackTrigger ControlID="btnClearFilter" EventName="Click" />
    </Triggers>
</asp:UpdatePanel>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

九厘米的零° 2024-10-01 20:14:16

这最终与嵌套的 TabContainer 完全无关。

在将相关控件添加到 TabContainer 之前,我不知不觉地破坏了它们,令人惊讶的是,这意味着它们无法像以前那样发挥作用。

抱歉浪费了大家的集体时间。

谢谢,
克利夫

This ended up being completely unrelated to nested TabContainers.

I had unknowingly broken the controls in question before adding them to the TabContainer and surprisingly, this meant they did not function the way they used to.

Sorry for wasting your collective time.

Thanks,
Clif

牵强ㄟ 2024-10-01 20:14:16

确保 TabContainer 的 OnDemand 属性已关闭。我知道,这可能会导致 GridView 等控件在保留其行的同时丢失数据,尤其是在动态生成控件时。

通过标记:

<asp:TabContainer ID="tcBanner" runat="server" ActiveTabIndex="0" Width="100%" 
    EnableViewState="False" ScrollBars="Vertical" OnDemand="false" >

通过代码:

tcBanner.OnDemand = false;

Make sure your TabContainer's OnDemand Property is turned off. I know for a fact that this can cause your controls such as GridView to lose their data while retain their rows, especially if you dynamically generate your controls.

Via Markup:

<asp:TabContainer ID="tcBanner" runat="server" ActiveTabIndex="0" Width="100%" 
    EnableViewState="False" ScrollBars="Vertical" OnDemand="false" >

Via code:

tcBanner.OnDemand = false;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文