在 Visual Studio 中复制现有 ASPX 页面的最佳方法
在 Visual Studio 的 Web 项目中创建现有 ASPX 页面的副本的最佳方法是什么?
如果我右键单击解决方案资源管理器中的 ASPX 文件并选择复制,然后粘贴,它看起来就像我所期望的那样。我获得了 ASPX 文件和代码隐藏文件的新副本。然后我可以重命名 ASPX 文件,文件背后的代码也会被重命名。
看起来不错,直到我打开 ASPX 文件。然后我看到它具有与原始文件相同的“继承”标记,并且它指向原始类名。
我有什么遗漏的吗?我意识到我可以手动编辑它以及文件后面的代码(因为它们声明相同的类名,这会导致构建错误)。有没有更好的方法来做到这一点,或者我应该振作起来并开始做一些手工工作? :-)
What is the best way to create a copy of an existing ASPX page in a web project in Visual Studio?
If I right click on the ASPX file in the Solution Explorer and select copy, then paste, it looks like what I was expecting. I get a new copy of the ASPX file and the code behind files. I can then rename the ASPX file and the code behind files get renamed as well.
Looking good, until I open the ASPX file. Then I see that it has the same "Inherits" tag that the original file had, and it points to the orginal class name.
Is there something that I am missing? I realize I can mannually edit this, and the code behind files (since they are declaring the same class name, which causes build errors). Is there a better way to do this, or should I just man up and start doing some manual work? :-)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我几乎总是创建一个全新的页面,然后只需复制“内容”(留下页面指令信息、命名空间等),然后根据需要进行一些查找和替换。
I almost always create a brand new page, then just copy the "guts" (leaving page directive info, namespaces, etc) followed shortly by some find and replace if needed.
以下工作在 VS 2013 中
The following works in VS 2013
我认为 Resharper 有一个“重复”重构功能,也适用于 ASPX。默认快捷键应该是 Ctrl-D
I think Resharper has a 'Duplicate' refactoring that works on ASPX's as well. The default shortcut should be Ctrl-D
我想通了 - 所以不需要答案,但我将其留在这里,因为我认为其他人可能会发现它有用。
我所做的是打开 aspx 页面 aspx.designer.vb 文件之一(对于我相同的代码隐藏文件来说,它们都是相同的)并复制自动生成的 WithEvents 控件声明。
然后,我将 aspx.vb 和 aspx.designer.vb 文件转换为空白文件(当我删除它们时,编译器抱怨它找不到它们 - 还不知道如何解决这个问题)。魔法!我的所有 aspx 文件现在都指向我的新类(和文件),并且我不再有重复的代码。
顺便说一句,这不仅仅是使用多层设计的情况。我已经将所有实质性代码集中在一处,但我仍然必须将 Page_Load 和各种控件单击函数的调用复制到该代码中。现在我没有任何重复的东西......
布莱恩
I figured it out - so no need for an answer, but I am leaving this here as I think others may find it useful.
What I did is to open one of the aspx page aspx.designer.vb files (they are all identical for my identical code-behind files) and copy the auto-generated WithEvents declarations for the controls.
I then turned the aspx.vb and aspx.designer.vb files into blank files (when I deleted them, the compiler complained that it couldn't find them - not sure yet how to fix that). Magic! All my aspx files now point to my new class (and file) and I no longer have the duplicated code.
By the way, this is not just a case of using multi-tier design. I already had all the substantive code in one place, but I still had to duplicate the calls from Page_Load and various control click functions into that code. Now I have nothing duplicated...
Brian
与布莱恩的回答类似。
在VS2013中。
您将看到一个新创建的 aspx,末尾带有“- Copy.aspx”
键入您希望新的 .aspx 的名称。继承等会自动更新。
Similar to Brian's answer.
In VS2013.
You'll see a new aspx created with the same with " - Copy.aspx" at the end
Type what you want the new .aspx called. Inherits, etc. are updated automatically.
我已经尝试过了,但失败了......所以我单独复制了 aspx 页面上的每个段落并将其粘贴到正确的位置
i allready try it and it faild.... so i copy every paragraph on the aspx page alone and paste it in the right place