简体   繁体   English

Visual Studio 2010禁用特定ascx控件的Designer代码生成

[英]Visual Studio 2010 Disable Designer Code Generation for particular ascx controls

I am currently developing a website for a Berkeley Club in Visual Studio 2010 Prof. Ed. 我目前正在使用Visual Studio 2010教授Ed。为伯克利俱乐部开发一个网站。 using Asp.net and Dotnetnuke v6. 使用Asp.net和Dotnetnuke v6。 This will be my second time encountering this specific problem/hassle. 这将是我第二次遇到此特定问题/麻烦。 I created a new control (ascx file) and have been working on it some. 我创建了一个新控件(ascx文件),并一直在进行一些工作。 I wanted to add the Dotnetnuke htmleditor since its sick so added the required code. 我想添加Dotnetnuke htmleditor,因为它生病了,所以添加了所需的代码。 Namely... 即...

<%@ Register TagPrefix="dnn" TagName="TextEditor" Src="~/controls/TextEditor.ascx"%>

<dnn:TextEditor ID="EmailContent" runat="server" Height="400px" Width="100%" />

I also had to change the ascs.designer.cs file so that instead of reading 我还必须更改ascs.designer.cs文件,以免读取

protected global::System.Web.UI.UserControl EmailContent;

it read like 它看起来像

protected global::DotNetNuke.UI.UserControls.TextEditor EmailContent;

This makes it use the DNN TextEditor which is what I want. 这使它使用了我想要的DNN TextEditor。 The problem is that whenever VS uses the designer to autogenerate code it overwrites the bottom line with the top line. 问题是,每当VS使用设计器自动生成代码时,它都会用顶行覆盖底行。 This means every time I change the ascx file I have to change the designer again. 这意味着每次我更改ascx文件时,都必须再次更改设计器。 This has gotten annoying, but I have not been able to find a way to fix it. 这变得很烦人,但是我一直找不到解决它的方法。 Any ideas on how to disable the VS designer for specific controls or for segments of code in a autogenerated designer file? 关于如何为特定控件或自动生成的设计器文件中的代码段禁用VS设计器的任何想法?

Put the EmailContent declaration in the ascx.cs file, and remove it from the ascx.designer.cs file. EmailContent声明放入ascx.cs文件中,然后将其从ascx.designer.cs文件中删除。 This will prevent the designer from messing up the type. 这将防止设计人员弄乱类型。

This goes to ascx.cs: 转到ascx.cs:

protected global::DotNetNuke.UI.UserControls.TextEditor EmailContent;

The problem is that Visual Studio is interpreting the path ~/ to mean the root of your project, instead of the root of the DotNetNuke website (how it will resolve at runtime). 问题是,Visual Studio是解释路径~/意味着你的项目的根,而不是DotNetNuke的网站的根目录(怎么会在运行时解决)。

If your module project that you're working on is located in a DotNetNuke site which is hosted in your local IIS, you can setup the project to know where it's actual root is. 如果您正在处理的模块项目位于本地IIS托管的DotNetNuke站点中,则可以将项目设置为知道其实际根目录在哪里。 In the project's properties, go to the Web tab and make sure that it's setup for IIS. 在项目的属性中,转到“ Web”选项卡,并确保已为IIS设置了它。 The project URL should be the URL to your module (eg http://mysite.dnndev.me/DesktopModules/MyModule ) and then check the "Override application root URL" checkbox and enter the website's root there (eg http://mysite.dnndev.me ). 项目URL应该是模块的URL(例如http://mysite.dnndev.me/DesktopModules/MyModule ),然后选中“ Override application root URL”复选框,然后在其中输入网站的根目录(例如http://mysite.dnndev.me )。 This should allow Visual Studio to realize where ~/controls/TextEditor.ascx points, and find the right type. 这应该使Visual Studio能够了解~/controls/TextEditor.ascx指向何处,并找到正确的类型。

That said, this works for us about 90% of the time, but we've had some projects where this doesn't work for whatever reason, and then we resort to @mika's answer of moving the declaration from the designer file to the codebehind file. 就是说,这对我们大约90%的时间有效,但是我们有一些项目无论出于什么原因都不起作用,然后我们诉诸于@mika的回答 ,将声明从设计器文件移至后台代码。文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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