我已经制作了一个自HtmlGenericControl继承的自定义Web控件,并添加了一个名为“ ViewRoles”的属性。 呈现控件后,也将属性Viewroles作为标记的属性呈现。
这是控件的代码
[
AspNetHostingPermission(SecurityAction.Demand,Level = AspNetHostingPermissionLevel.Minimal),
AspNetHostingPermission(SecurityAction.InheritanceDemand,Level = AspNetHostingPermissionLevel.Minimal),
DefaultProperty("TagName"),
ToolboxData("<{0}:HtmlGenericControl runat=\"server\" ID=\"EDKHGC\" TagName=\"\"></{0}:HtmlGenericControl>")
]
public class HtmlGenericControl : System.Web.UI.HtmlControls.HtmlGenericControl, IVisible
{
/// <summary>
/// Main constructor
/// </summary>
/// <param name="tag">Name of the Tag</param>
public HtmlGenericControl(string tag)
: base(tag)
{
}
private string _viewRoles;
[Bindable(true), Category("Security"), DefaultValue(""), Description("Roles allowed to view the control")]
public string ViewRoles
{
get
{
if (string.IsNullOrEmpty(_viewRoles) && ViewState["viewRoles"] != null)
_viewRoles = ViewState["viewRoles"].ToString();
return _viewRoles;
}
set
{
_viewRoles = value;
ViewState["viewRoles"] = value;
}
}
如果我使用实例化页面中的控件
<cc1:HtmlGenericControl tagname="div" ViewRoles="CustomRole" runat="server" id="myid"></cc1:HtmlGenericControl>
控件呈现为
<div id="myid" viewRoles="CustomRole">
我希望在运行时不呈现属性“ ViewRoles”。 是否有特定的属性?否则如何避免呈现该属性?