如何将aspx或母版页文件转换为页面和代码?

时间:2022-10-16 15:52:54

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.

我有一个项目,其中创建.master页面没有代码隐藏页面。现在,我想为此.master页面添加一个代码页面,并将“in page”代码移动到代码隐藏文件。这样做的最佳/最简单的方法是什么?我正在使用Visual Studio 2008。

3 个解决方案

#1


3  

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.

创建新的类文件,将其命名为yourmaster.master.cs(Visual Studio将自动将其与.master分组)并将代码移动到它,在您的母版页中引用它。

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

然后右键单击您的项目并单击“转换为Web应用程序”,Visual Studio将创建设计器文件。

#2


0  

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.

一种方法是创建一个新的空母版页/ aspx文件,然后将已有的代码复制粘贴到该页面中。这将负责所有连线和创建代码文件。

#3


0  

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).

或者,您可以在创建文件后面的适当代码(.master.cs或.aspx.cs或VB.NET .master.vb或.aspx.vb)时调整Page或Master指令。

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

我不知道一个简单的点击方式来实现这一目标。

#1


3  

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.

创建新的类文件,将其命名为yourmaster.master.cs(Visual Studio将自动将其与.master分组)并将代码移动到它,在您的母版页中引用它。

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

然后右键单击您的项目并单击“转换为Web应用程序”,Visual Studio将创建设计器文件。

#2


0  

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.

一种方法是创建一个新的空母版页/ aspx文件,然后将已有的代码复制粘贴到该页面中。这将负责所有连线和创建代码文件。

#3


0  

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).

或者,您可以在创建文件后面的适当代码(.master.cs或.aspx.cs或VB.NET .master.vb或.aspx.vb)时调整Page或Master指令。

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

我不知道一个简单的点击方式来实现这一目标。