如果是的MasterType设置如何解决与自动生成的主属性的名称空间问题 [英] How to fix namespace problem with autogenerated Master property if MasterType is set
问题描述
有这个问题星期后,我终于决定寻求一个解决问题如下:
after weeks of having this issue I finally decided to ask for a solution to the following problem:
在.aspx页面中,您可以设置
In the .aspx page you can set
<%@ MasterType VirtualPath="~/Mastername.master" %>
这会导致一个自动生成的属性在.aspx.designer
This results in an auto generated property in the .aspx.designer
public new Mastername Master {
get {
return ((Masternamee)(base.Master));
}
}
工作完全正常。但是,如果我做.aspx文件的变化,楼市将产生新的汽车,它看起来像下面这样:
Works perfectly fine. But if I do changes in the .aspx file, the property will be new auto generated and it looks like the following:
public new NAMESPACE1.Mastername Master {
get {
return ((NAMESPACE1.Mastername)(base.Master));
}
}
编译将是不可能的之后,因为对于母版的类不能在给定的命名空间来解决。
母版有NAMESPACE1的命名空间。
Compiling will not be possible afterwards, because the class for the MasterPage cannot be resolved at the given namespace. The masterpage has NAMESPACE1 as namespace.
每contentpage具有相同NAMESPACE1。
自动生成的属性试图寻找在NAMESPACE1.NAMESPACE1母版类会失败,因为它不存在。当然,我可以删除第一个NAMESPACE1。再次使应用程序编译,但它只是吮吸这几乎使我在.aspx文件的更改都必须这样做。
Every contentpage has the same NAMESPACE1. The autogenerated property tries to look for the masterpage class in NAMESPACE1.NAMESPACE1 which will fail, due to it does not exist. Of course I can remove the first NAMESPACE1. to make the app compilable again, but it just sucks to do this nearly every time I make changes in the .aspx file.
有没有办法来避免这个问题?我能想到的唯一办法,是无视自动生成的属性,并作出明确的转换,每次我想有机会获得母版。
Is there a way to avoid this problem? The only way I can think of, is to ignore the auto generated property and make a explicit cast everytime I want have access to the masterpage.
编辑:我使用Visual Studio 2008专业SP1
I'm using Visual Studio 2008 Professional SP1.
推荐答案
我发现的解决方案。我不会在designerfile使用自动生成的属性。我会写,我做每一个contentpage实现我自己的包装属性。
I found a solution that works. I won't use the autogenerated property in the designerfile. I'll write my own wrapper property that I do implement in every contentpage.
这篇关于如果是的MasterType设置如何解决与自动生成的主属性的名称空间问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!