views:

23

answers:

1

I have a template for a website, and I want to edit the aspx files with C#, thats means that I want each of the aspx files have a code behind file, which is .aspx.cs file for each .aspx exist file.

I opened a new ASP.NET AJAX Website Template and copied the .aspx files, the webconfig and the css to the new website I created.

when I add control and double-click on it in order to create a .aspx.cs file for this page, it brings me to the source code.

I've added this line as the first line of my aspx file in order to create a .aspx.cs file:

<%@ Page Language="C#" AutoEventWireup="true"
    CodeFile="Login.aspx.cs" Inherits="Login" %>

but still it dont let me create an aspx.cs file. Does someone know how can I do that?

A: 
  • Right click the folder your ASPX page is in (or the root project if it's in the root folder) and pick "Add New Item..."
  • Choose "Class", name it Login.aspx.cs, and click "Add"
    • If you're using a Website Project, it will ask you if you wanted to put the code file in app_code. Answer no.
  • Change the class declaration to match the Inherits property in your page directive, be a partial, and inherit from WebForms' Page base class:

    public partial class Login : System.Web.UI.Page
    {
    
    
    }
    
Dave Ward
Keyboard shortcut: F7
rchern
F7 won't work in a situation like Aviran had, where there's no code-behind file to switch to.
Dave Ward