【发布时间】:2018-03-06 16:08:11
【问题描述】:
我正在尝试创建自定义 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>
我要替换的代码
<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>
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>
【问题讨论】:
-
你也可以看看复合控件。我不喜欢这个解决方案。仅对这三个控件来说是非常不可读和难以管理的。最好的解决方案是使用用户控件 (ascx)
标签: asp.net .net webforms user-controls web-controls