问题
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