创建自定义Web控件

时间:2017-09-25 15:57:35

标签: asp.net .net webforms user-controls web-controls

我正在尝试创建自定义Web控件,但我对Web窗体的使用经验有限。如何访问打开关闭标记之间传递的文本?控件应该像这样工作。

用法

<asp:YesOrNoQuestion>Are you above the age of 18 ? </asp:YerOrNoQuestion>

控制

<tr id="trQ6CA" runat="server" visible="false">
    <td>
        <asp:Label ForeColor="Black" ID="QuestionLabel" runat="server">
          // Question Goes Here
        </asp:Label>
    </td>
    <td>
        <asp:RadioButtonList ID="buttonCollection" runat="server" RepeatDirection="Horizontal">
            <asp:ListItem Value="Y">Yes</asp:ListItem>
            <asp:ListItem Value="N">No</asp:ListItem>
        </asp:RadioButtonList>
    </td>
    <td>
        <asp:RequiredFieldValidator ControlToValidate="buttonCollection" ID="Requiredfieldvalidator" InitialValue="" runat="server" Text="*" ValidationGroup="vgApplication">
            *
        </asp:RequiredFieldValidator>
    </td>
</tr>

代码I&#39; m替换

<tr id="trQ6CA" runat="server" visible="false">
    <td valign="top" align="left">
        <asp:Label ID="Label10" runat="server" ForeColor="Black">
            <b>DOES THE PROPOSED INSURED:</b> 
            &nbsp;Have a comprehensive health benefits from an insurance policy, an HMO plan, or employer health benefit plan? <br />
            If No, persons without such comprehensive coverage are not eligible for this insurance policy.
        </asp:Label>
    </td>
    <td valign="top">
        <asp:RadioButtonList ID="rbtQ6S1" runat="server" RepeatDirection="Horizontal">
            <asp:ListItem Value="Y">Yes</asp:ListItem>
            <asp:ListItem Value="N">No</asp:ListItem>
        </asp:RadioButtonList>
    </td>
    <td valign="top">
        <asp:RequiredFieldValidator ID="Requiredfieldvalidator65" runat="server" Text="*" ControlToValidate="rbtQ6S1" InitialValue="" ValidationGroup="vgApplication">
            *
        </asp:RequiredFieldValidator>
    </td>
</tr>

1 个答案:

答案 0 :(得分:1)

注册控件时,您可以选择前缀和标记: https://msdn.microsoft.com/en-us/library/sbz9etab.aspx