繁体   English   中英

在后面的代码中设置自定义用户控件的属性

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM