views:

630

answers:

3

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.

A: 

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.

Espo
A: 

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.

Andrei Rinea
+3  A: 

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.

FlySwat
And just confirming this is safe to use in an MVC application that also has regular ASP.NET web pages (eg. if you are using the ReportViewer control). All view .aspx pages are left alone.
David Gardiner