How do you convert an aspx or master page file to page and code behind?

倖福魔咒の 提交于 2019-12-11 01:58:09

问题


I have a project where a .master page was created without a code behind page. Now I want to add a code behind page for this .master page and move the "in page" code to the code behind file. What is the best/easiest way to go about doing this? I'm using Visual Studio 2008.


回答1:


Create new class file, name it yourmaster.master.cs (Visual Studio will automaticly group it with the .master) and move the code to it, reference it in your masterpage.

Then rightclick on your project and click "Convert to Web Application" and Visual Studio will create the designer file.




回答2:


One way to do it, is to create a new empty masterpage/aspx-file and then copy-paste the code you allready have into that page. That will take care of all the wire-up and creating of code-files.




回答3:


Or you can adapt the Page or Master directive while creating an appropiate code behind file (.master.cs or .aspx.cs or for VB.NET .master.vb or .aspx.vb).

I don't know of a simple click way to achieve this.



来源:https://stackoverflow.com/questions/46938/how-do-you-convert-an-aspx-or-master-page-file-to-page-and-code-behind

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!