2013-01-12 105 views
1

的代码,我发现这个问题,表明在自定义用户控件(ASCX)属性可以在线指派为HTML属性:Custom attribute in 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"; 
     } 

这就是我想做的事情,但它不工作。这可能吗?

回答

0

Do'h!这实际上起作用。我想Visual Studio不是自动生成控件。只需将protected NavBar MyNavBar;添加到我的页面顶部即可解决问题。我希望别人觉得这很有用。

相关问题