Create code behind file after aspx has been created
I don't know of an automated way to do this, but if there is no server side code in the existing *.aspx files then it should just be a case of adding the .cs codebehind files and then wiring them up in the <%@ Page
tag like so:
<%@ Page Title="YourPageTitle" Language="C#" AutoEventWireup="true" CodeBehind="YourPage.aspx.cs" Inherits="YourNamespace.YourPage" %>
Note: This will not create the YourPage.aspx.designer.cs
file. (I usually delete these anyway as they cause merge issues - i find it easier to add the controls i need to reference to my code-behind file manually.)
The other alternative is to just create a new "Web Form" for each page with the correct names and then copy and paste the existing markup into them. If you do have server code in the existing *.aspx files then you will need to manually copy it to the code-behind.
After you add the new .cs file, you may want to see the file look like a codebehind file (indented, icon, etc). To do so:
- Unload the project
- Edit the project
- Find the new filename (file.aspx.cs) in the section with files.
- Add an xml node for DependentUpon.
- Save and Close the project
- Reload the project
For a file Profile.aspx.cs, the xml should look something like this:
<Compile Include="Profile.aspx.cs">
<DependentUpon>Profile.aspx</DependentUpon>
<SubType>ASPXCodeBehind</SubType>
</Compile>
Based on what I found here: http://forums.asp.net/t/1229894.aspx/1
- Right click on your solution explorer.
- Add New Item -> Class File.
- Name the file as the name of your aspx eg: Default.aspx.cs
- When it asks you the file should be in app_code click "no".
In your aspx in page attribute add
AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default"
Similarly in your class file that you just added remove everything. Your class should look like this:
//all namespaces go here public partial class Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } }