How to add custom inner tag in ASP.NET Web UserControl

67 views Asked by At

I am creating a new Web UserControl in my ASP.NET Web Form project (using VB.NET). Normally, I could add custom attributes to my UserControl like in the solution for this question.

However, when it comes to the properties of the child controls, the name of each attribute becomes quite long as I tried to include the control name in it.

For example, I have simple user control like this:

<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="MyControl.ascx.vb" 
    Inherits="Web.MyControl" %>

<asp:Panel ID="pnl_Filter" runat="server">
    <div class="d-flex row">
        <div class="col-1">
            <asp:Label ID="lbl_Subject" runat="server" Text="Subject" Font-Bold="true" />
        </div>
        <div class="col-5">
            <asp:DropDownList ID="ddl_Subject" runat="server" 
                DataSourceID="ods_Subject" 
                DataTextField="subject_name" 
                DataValueField="subject_id">
            </asp:DropDownList>
            <asp:ObjectDataSource ID="ods_Subject" runat="server"
                TypeName="Web.SubjectManager" 
                SelectMethod="GetSubjectList" />
        </div>
        ....
    </div>
</asp:Panel>

I wonder if I could create custom inner tag inside my UserControl so, when I place it in parent page, I could do something like this:

<uc:MyControl ID="mc_filter" runat="server">
    <LabelProperties Text="Subject" Font-Bold="true" />
    <DropdownProperties DataSourceID="ods_Subject"
        DataTextField="subject_name" 
        DataValueField="subject_id" />
</uc:MyControl>
0

There are 0 answers