简体   繁体   中英

Scope of controls in asp.net content blocks

Just ran into some interesting problem. I've separated a panel from a asp:Content block to another. In the original asp:Content block still resides a asp:FormView with childs, which references multiple ObjectDataSources. These ObjectDataSource are defined in the same asp:Content block.

The separated panel has child controls which are using the same ObjectDataSources. However, because of the separation, these ObjectDataSources aren't accessible anymore...

Simplified situation:

<asp:Content ID="ContentsContent" ContentPlaceHolderID="ContentsContainer" runat="server">
    <asp:FormView DataSourceID="FirstSource">
        <asp:DropDownList DataSourceID="SecondSource" />
    </asp:FormView>
    <asp:ObjectDataSource ID="FirstSource" />
    <asp:ObjectDataSource ID="SecondSource" />
</asp:Content>
<asp:Content ID="ModelBoxesContent" ContentPlaceHolderID="ModalBoxesContainer" runat="server">
    <asp:Panel>
        <asp:DropDownList DataSourceID="SecondSource" />
    </asp:Panel>
</asp:Content>

I understand that the scope of this Content blocks doesn't allow it... But does anyone have a nice solution to define the same datasource at one place, but still be able to reference them in multiple Content blocks?

Thanks.

设置页面加载时的数据源ID

seconddropdownlist.DataSourceID="SecondSource"  ;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM