.net 母版页 .cs 无法在 .aspx 页面上找到控件
我有一个母版页,我正在重用它来创建一个新项目。它在项目 A 中完美运行。但是,在项目 BI 中,我收到编译错误,指出该控件在当前上下文中不存在。这让我很困惑。在 aspx 页面上,控件看起来像:
<asp:Menu
ID="Menu1"
Orientation="Horizontal"
runat="server"
Font-Bold="true"
ForeColor="#9B301C"
CssClass="noAunderline"
DynamicHoverStyle-BackColor="#ffff00"
DynamicHoverStyle-Font-Bold="false"
DynamicMenuItemStyle-Font-Bold="false" DynamicHoverStyle-Font-Underline="false"
StaticHoverStyle-BackColor="#ffff00"
StaticEnableDefaultPopOutImage="true"
DynamicHoverStyle-Width="200"
DynamicEnableDefaultPopOutImage="true"
Target="_top"
onmenuitemclick="Menu1_MenuItemClick">
<StaticMenuStyle
BackColor="#ffffff"
BorderStyle="None"
BorderColor=""
BorderWidth="0"
Width="200"
CssClass="noAunderline" />
<DynamicMenuStyle
BackColor="#ffffff"
BorderStyle="Solid"
BorderColor="#aaaaaa"
BorderWidth="1"
Font-Underline="false"
Width="200"
CssClass="noAunderline" />
</asp:Menu>
在后面的代码上,我有:
private MenuItem MenuAddRootItem(string NavName, string value, string imageURL, string NavLink, string target)
{
MenuItem MasterItem = new MenuItem(NavName, value, imageURL, NavLink, target);
Menu1.Items.Add(MasterItem);
return MasterItem;
}
我的同事建议之前解决同样的问题,迄今为止找到的唯一解决方案是创建一个新项目并复制代码。我更愿意找到一个更明确的解决方案。还有其他人看到这个问题吗?
谢谢!
I have a masterpage that I am reusing to create a new project. It works perfectly in project A. However, in project B I am getting a compile error saying the control does not exist in the current context. It baffles me. On the aspx page the control looks like:
<asp:Menu
ID="Menu1"
Orientation="Horizontal"
runat="server"
Font-Bold="true"
ForeColor="#9B301C"
CssClass="noAunderline"
DynamicHoverStyle-BackColor="#ffff00"
DynamicHoverStyle-Font-Bold="false"
DynamicMenuItemStyle-Font-Bold="false" DynamicHoverStyle-Font-Underline="false"
StaticHoverStyle-BackColor="#ffff00"
StaticEnableDefaultPopOutImage="true"
DynamicHoverStyle-Width="200"
DynamicEnableDefaultPopOutImage="true"
Target="_top"
onmenuitemclick="Menu1_MenuItemClick">
<StaticMenuStyle
BackColor="#ffffff"
BorderStyle="None"
BorderColor=""
BorderWidth="0"
Width="200"
CssClass="noAunderline" />
<DynamicMenuStyle
BackColor="#ffffff"
BorderStyle="Solid"
BorderColor="#aaaaaa"
BorderWidth="1"
Font-Underline="false"
Width="200"
CssClass="noAunderline" />
</asp:Menu>
And on the code behind I have:
private MenuItem MenuAddRootItem(string NavName, string value, string imageURL, string NavLink, string target)
{
MenuItem MasterItem = new MenuItem(NavName, value, imageURL, NavLink, target);
Menu1.Items.Add(MasterItem);
return MasterItem;
}
My colleagues suggest battling the same issue before, and the only solution found thus far is to create a new project and copy the code over. I would prefer to find a more definitive solution. Anyone else seen this issue?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,看来从项目中删除母版页,然后在 Visual Studio 中添加一个新的母版页并复制骨架内的代码就可以了。我认为 Designer.cs 文件未正确移植到项目中。
ok it seems that deleting the master page out of the project and then add a new masterpage in visual studio and copying the code inside the skeleton did the trick. I'm thinking the designer.cs file wasn't properly ported into the project.
是的,这通常是 Designer.cs 问题 - 控件的字段名称没有在那里声明。
Yep, its usually a designer.cs problem - Control's field name isn't declared there.