So I'm having problems when I try to publish the website. I'm in visual studio 2008 sp1.
所以当我尝试发布网站时,我遇到了问题。我在visual studio 2008 sp1。
I've got a bunch of user controls and on a few pages I'm using them programatically.
我有一堆用户控件,在几个页面上我以编程方式使用它们。
I've got a reference on the aspx page
我在aspx页面上有一个参考
<%@ Reference Control="~/UserControls/Foo.ascx" %>
Then on the code behing I use
然后在我使用的代码behing上
ASP.usercontrols_foo newFoo control = (ASP.usercontrols_foo)Page.LoadControl("~/UserControls/Foo.ascx");
If I navigate to the page it works fine, but when I goto publish the website I get a compile time error.
如果我导航到页面它工作正常,但当我转到发布网站时,我得到一个编译时错误。
8 个解决方案
#1
Argh, I'm bleeding development hours on this same issue. Does anyone have a solution to this ?
唉,我在同一个问题上的开发时间正在减少。有人有解决方案吗?
BTW: It builds if you uncheck "Allow this precompiled site to be updatable" (Right-click on the website, choose Property Pages, MSBuild Option)
顺便说一句:如果取消选中“允许此预编译站点可更新”,则会构建它(右键单击网站,选择“属性页”,“MSBuild选项”)
But I need the site to be updatable.
但我需要网站可更新。
#2
I had this same problem - actually, in my case I could get it to compile and build my website, but it would blow up spectacularly when doing an automated build.
我遇到了同样的问题 - 实际上,在我的情况下,我可以让它来编译和构建我的网站,但是在进行自动构建时它会非常爆炸。
Try replacing your code as follows:
尝试更换代码,如下所示:
ASP.usercontrols_foo newFoo control = (ASP.usercontrols_foo)Page.LoadControl("~/UserControls/Foo.ascx");
with
USERCONTROLS_Foo newFoo control = (USERCONTROLS_Foo)Page.LoadControl("~/UserControls/Foo.ascx");
(Capitalization will be based on how you capitalized your directory name/control name - but in either case should highlight appropriately).
(大小写将基于您的目录名称/控件名称的大写 - 但在任何一种情况下都应该适当地突出显示)。
#3
Specify a namespace for user control (see Dynamically Load a user control (ascx) in a asp.net website ).
为用户控件指定命名空间(请参阅在asp.net网站中动态加载用户控件(ascx))。
#4
I've found a solution for it. If i'll declare controls in user defined namespace, then I can use controls directly without using ASP or referencing it into aspx page.
我找到了解决方案。如果我将在用户定义的命名空间中声明控件,那么我可以直接使用控件而无需使用ASP或将其引用到aspx页面。
#5
It may have something to do with the specific type not being available. Can you change the control reference so the type and cast just use the base Control class:
它可能与特定类型不可用有关。你可以更改控件引用,所以类型和强制转换只使用基类Control类:
Control control = Page.LoadControl("~/UserControls/Foo.ascx");
#6
Yes, I can cast it to Control. But then I lose direct access to the methods on the usercontrol.
是的,我可以将它投射到Control。但后来我失去了对usercontrol方法的直接访问权限。
I know that I can access the methods by reflecting into the control, and I've successfully done that but that's far from ideal to access all the other user controls on the site.
我知道我可以通过反映到控件中来访问这些方法,并且我已经成功地完成了这项工作,但是访问网站上的所有其他用户控件远非理想。
Also, the follow-up error is that it cant find the usercontrols that on the markup
此外,后续错误是它无法找到标记上的用户控件
<%@ Register src="CategoryRows.ascx" tagname="CategoryRows" tagprefix="abc" %>
<abc:CategoryRows ID="CategoryRows" runat="server" />
Note that I can run the site successfully both locally and on the server if I essentially XCopy the entire site (source code and all). But Publish fails.
请注意,如果我基本上对整个站点进行XCopy(源代码和所有站点),我可以在本地和服务器上成功运行站点。但是Publish失败了。
#7
Casting the user control may create many problem .my approach is to create a class (say control Class) put all the properties and method you need after casting and inherit this class from System.Web.UI.UserControl .Then in your user cotrol code file instead of System.Web.UI.UserControl user this control class .
转换用户控件可能会产生许多问题。我的方法是创建一个类(比如控件类),在转换后放置所需的所有属性和方法,并从System.Web.UI.UserControl继承此类。然后在您的用户cotrol代码中文件而不是System.Web.UI.UserControl用户这个控件类。
now when ever you need casting cast with this class only . it will be light casting as well.
现在什么时候你只需要使用这个类进行强制转换。它也将是轻型铸造。
#8
Please check:
Do you have any website.publishproj
file?
If it exists, then delete and try again and publish code.
你有任何website.publishproj文件?如果存在,则删除并再次尝试并发布代码。
#1
Argh, I'm bleeding development hours on this same issue. Does anyone have a solution to this ?
唉,我在同一个问题上的开发时间正在减少。有人有解决方案吗?
BTW: It builds if you uncheck "Allow this precompiled site to be updatable" (Right-click on the website, choose Property Pages, MSBuild Option)
顺便说一句:如果取消选中“允许此预编译站点可更新”,则会构建它(右键单击网站,选择“属性页”,“MSBuild选项”)
But I need the site to be updatable.
但我需要网站可更新。
#2
I had this same problem - actually, in my case I could get it to compile and build my website, but it would blow up spectacularly when doing an automated build.
我遇到了同样的问题 - 实际上,在我的情况下,我可以让它来编译和构建我的网站,但是在进行自动构建时它会非常爆炸。
Try replacing your code as follows:
尝试更换代码,如下所示:
ASP.usercontrols_foo newFoo control = (ASP.usercontrols_foo)Page.LoadControl("~/UserControls/Foo.ascx");
with
USERCONTROLS_Foo newFoo control = (USERCONTROLS_Foo)Page.LoadControl("~/UserControls/Foo.ascx");
(Capitalization will be based on how you capitalized your directory name/control name - but in either case should highlight appropriately).
(大小写将基于您的目录名称/控件名称的大写 - 但在任何一种情况下都应该适当地突出显示)。
#3
Specify a namespace for user control (see Dynamically Load a user control (ascx) in a asp.net website ).
为用户控件指定命名空间(请参阅在asp.net网站中动态加载用户控件(ascx))。
#4
I've found a solution for it. If i'll declare controls in user defined namespace, then I can use controls directly without using ASP or referencing it into aspx page.
我找到了解决方案。如果我将在用户定义的命名空间中声明控件,那么我可以直接使用控件而无需使用ASP或将其引用到aspx页面。
#5
It may have something to do with the specific type not being available. Can you change the control reference so the type and cast just use the base Control class:
它可能与特定类型不可用有关。你可以更改控件引用,所以类型和强制转换只使用基类Control类:
Control control = Page.LoadControl("~/UserControls/Foo.ascx");
#6
Yes, I can cast it to Control. But then I lose direct access to the methods on the usercontrol.
是的,我可以将它投射到Control。但后来我失去了对usercontrol方法的直接访问权限。
I know that I can access the methods by reflecting into the control, and I've successfully done that but that's far from ideal to access all the other user controls on the site.
我知道我可以通过反映到控件中来访问这些方法,并且我已经成功地完成了这项工作,但是访问网站上的所有其他用户控件远非理想。
Also, the follow-up error is that it cant find the usercontrols that on the markup
此外,后续错误是它无法找到标记上的用户控件
<%@ Register src="CategoryRows.ascx" tagname="CategoryRows" tagprefix="abc" %>
<abc:CategoryRows ID="CategoryRows" runat="server" />
Note that I can run the site successfully both locally and on the server if I essentially XCopy the entire site (source code and all). But Publish fails.
请注意,如果我基本上对整个站点进行XCopy(源代码和所有站点),我可以在本地和服务器上成功运行站点。但是Publish失败了。
#7
Casting the user control may create many problem .my approach is to create a class (say control Class) put all the properties and method you need after casting and inherit this class from System.Web.UI.UserControl .Then in your user cotrol code file instead of System.Web.UI.UserControl user this control class .
转换用户控件可能会产生许多问题。我的方法是创建一个类(比如控件类),在转换后放置所需的所有属性和方法,并从System.Web.UI.UserControl继承此类。然后在您的用户cotrol代码中文件而不是System.Web.UI.UserControl用户这个控件类。
now when ever you need casting cast with this class only . it will be light casting as well.
现在什么时候你只需要使用这个类进行强制转换。它也将是轻型铸造。
#8
Please check:
Do you have any website.publishproj
file?
If it exists, then delete and try again and publish code.
你有任何website.publishproj文件?如果存在,则删除并再次尝试并发布代码。