Visual Studio 2010 禁用特定 ascx 控件的设计器代码生成

发布于 2024-12-01 06:48:00 字数 797 浏览 1 评论 0原文

我目前正在 Visual Studio 2010 Prof. Ed 中为 Berkeley Club 开发一个网站。使用 Asp.net 和 Dotnetnuke v6。这将是我第二次遇到这个特定的问题/麻烦。我创建了一个新的控件(ascx 文件)并对其进行了一些工作。我想添加 Dotnetnuke htmleditor,因为它有问题,所以添加了所需的代码。也就是说...

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

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

我还必须更改 ascs.designer.cs 文件,这样就不会

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

像这样读取它,

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

这使得它使用我想要的 DNN TextEditor。问题是,每当 VS 使用设计器自动生成代码时,它都会用顶行覆盖底行。这意味着每次我更改 ascx 文件时,我都必须再次更改设计器。这已经很烦人了,但我还没有找到解决方法。关于如何针对特定控件或自动生成的设计器文件中的代码段禁用 VS 设计器有什么想法吗?

I am currently developing a website for a Berkeley Club in Visual Studio 2010 Prof. Ed. using Asp.net and 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. I wanted to add the Dotnetnuke htmleditor since its sick so added the required code. 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

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. The problem is that whenever VS uses the designer to autogenerate code it overwrites the bottom line with the top line. This means every time I change the ascx file I have to change the designer again. 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

魂牵梦绕锁你心扉 2024-12-08 06:48:00

EmailContent 声明放入 ascx.cs 文件中,并将其从 ascx.designer.cs 文件中删除。这将防止设计者弄乱类型。

这转到 ascx.cs:

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

Put the EmailContent declaration in the ascx.cs file, and remove it from the ascx.designer.cs file. This will prevent the designer from messing up the type.

This goes to ascx.cs:

protected global::DotNetNuke.UI.UserControls.TextEditor EmailContent;
夜访吸血鬼 2024-12-08 06:48:00

问题在于 Visual Studio 将路径 ~/ 解释为您的项目的根目录,而不是 DotNetNuke 网站的根目录(它将如何在运行时解析) 。

如果您正在处理的模块项目位于本地 IIS 中托管的 DotNetNuke 站点中,您可以设置该项目以了解其实际根目录在哪里。在项目的属性中,转到“Web”选项卡并确保它已针对 IIS 设置。项目 URL 应该是您的模块的 URL(例如 http://mysite.dnndev.me/DesktopModules/MyModule),然后选中“覆盖应用程序根 URL”复选框并在其中输入网站的根目录(例如http://mysite.dnndev.me)。这应该允许 Visual Studio 识别 ~/controls/TextEditor.ascx 指向的位置,并找到正确的类型。

也就是说,这对我们来说大约 90% 的时间都有效,但是我们有一些项目由于某种原因这不起作用,然后我们求助于 @mika 的将声明从设计器文件移动到代码隐藏文件的答案

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).

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. In the project's properties, go to the Web tab and make sure that it's setup for IIS. The project URL should be the URL to your module (e.g. http://mysite.dnndev.me/DesktopModules/MyModule) and then check the "Override application root URL" checkbox and enter the website's root there (e.g. http://mysite.dnndev.me). This should allow Visual Studio to realize where ~/controls/TextEditor.ascx points, and find the right type.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文