[英]Can not access my user controls' properties
我有一個用戶控件:
<%@ Control Language="C#" ClassName="WebUserControl" %>
<script runat="server">
public string name { get; set; }
</script>
然后在頁面上我有
<%@ Register Src="~/Controls/my_control.ascx" TagName="MyControl" TagPrefix="Me"%>
<Me:MyControl runat="server" ID="myControl1" />
我可以看到物業
<Me:MyControl runat="server" ID="myControl1" name="Hello World"/>
但是,如果從我的代碼后面或代碼標簽中嘗試
myControl1.name
我什么都沒有。 我究竟做錯了什么?
請嘗試以下方法:
這與控制狀態有關:
public string name
{
get
{
object obj = ViewState["name"];
return (obj == null) ? "" : obj.ToString();
}
set
{
ViewState["name"] = value;
}
}
您可以在此處找到其他信息:
工作正常。 您是否將控件拖放到窗體上 ?
您在頁面中缺少using
指令。 添加一個using {your.control.namespace}
語句。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.