【问题标题】:Adding "Attributes" to UserControl将“属性”添加到 UserControl
【发布时间】:2014-08-29 06:05:15
【问题描述】:

我希望在我的 ASP.Net 页面上创建 UserControl 时为其添加属性。我将如何做到这一点,然后我将如何在我的 .ascx 的代码隐藏中访问它们?

在 web.config 中: <add tagPrefix="uc" src="~/usercontrols/uc-EmailForm.ascx" tagName="EmailForm"/>

在页面上: <uc:EmailForm ID="EmailForm" runat="server" />

页面目标: <uc:EmailForm ID="EmailForm" runat="server" ShowTo="False" />

代码隐藏目标: pnlToAddress.Visible = ShowTo

【问题讨论】:

    标签: asp.net vb.net user-controls visual-studio-2005 ascx


    【解决方案1】:

    假设你的班级是这样的

     [ToolboxData("<{0}:BilingualLabel runat=server></{0}:BilingualLabel>")]
    public class BilingualLabel : System.Web.UI.WebControls.Label   {
    
    [Bindable(true), 
        Category("Appearance"),
        DefaultValue("EnglishText"),
        Description("English version of the text")] 
        public string Text_en {
            get {
                return text         }
            set {
                text = value            }
    
        }
    

    【讨论】:

      【解决方案2】:

      您必须在用户控件的类中创建公共属性(在 ascx.cs 中):

      public bool ShowTo { get; set; }
      

      【讨论】:

      • 我认为可能是这种情况,但找不到任何地方说它是。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-02
      相关资源
      最近更新 更多