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. 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 开发者_如何学Cwith 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?
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;
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.
精彩评论