[英]Set a property of a custom user control in the code behind
我發現這個問題表明可以將自定義用戶控件(ascx)上的屬性作為HTML屬性內聯分配: UserControl(* .ascx)中的自定義屬性?
這很好用,但是如果我在頁面上注冊了自定義用戶控件,並希望在后面的代碼中從該控件設置/獲取屬性該怎么辦?
ASPX:
<%-- I can assign ActivePage inline and this works fine --%>
<wd:NavBar ID="MyNavBar" runat="server" ActivePage="navbarItem1" />
ASPX.CS:
// I need to change the ActivePage
if (what == "internal")
{
RunInternalComparison();
MyNavBar.ActivePage = "navbarItem1";
}
else if (what == "external")
{
RunExternalComparison();
MyNavBar.ActivePage = "navbarItem2";
}
那就是我想做的,但是沒有用。 這可能嗎?
h! 這實際上有效。 我猜Visual Studio不是自動生成控件。 只需添加protected NavBar MyNavBar;
我的頁面頂部解決了該問題。 我希望其他人覺得這很有用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.