How to generate .cs from .aspx?

Discussion in 'C#' started by sxcnelson, Oct 13, 2009.

  1. #1
    I created new website I had unchecked "Place code in seperate file "

    Now I have code within .aspx pages .
    I want to generate .cs from for this website.
    Can anyone help me out?
     
    sxcnelson, Oct 13, 2009 IP
  2. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #2
    camjohnson95, Oct 13, 2009 IP
  3. Bulkish

    Bulkish Peon

    Messages:
    51
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Maybe there's an easier method but this is what I would do:

    If the .aspx file is not in production/live yet you can do this:

    1. Rename the .aspx file that does not have code-behind to something like "DefaultOLD.aspx"
    2. Create a new Web Form, with the original name you had on your original file and make sure you select this time the "Place code in seperate file"
    3. Open your original file, the one with the "OLD" in it's name and copy all of it's runat=server script and placed it inside the class of your new code-behind file
    3. The same as #3 but this time you copy only the HTML and paste it in the newly created .aspx file's html area
    4. Double check that any namespaces and/or UserControls you have registered in your original (no-codebehind) file is properly transfered into your new webform

    Let me know if you solved it via an easier way or are stuck in the 'process' of the previous steps
     
    Bulkish, Oct 13, 2009 IP
  4. urstop

    urstop Peon

    Messages:
    224
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I don't think there is any easy way of doing this. You will have to manually do it by seperating the C# and HTML markup into seperate files.
     
    urstop, Oct 15, 2009 IP
  5. wren

    wren Guest

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    1) create a new .cs file and name it something, lets call it see.cs with the namespace of Default2 or whatever is ur main namespace
    then edit the file so it looks like:
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Text;
    
    public partial class Default2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
    }
    
    Code (markup):
    2) then in the aspx markup code, change
    
    <%@ Page Language="C#" %>
    
    Code (markup):
    to:

    
    <%@ Page Title="" Language="C#" AutoEventWireup="true" CodeFile="see.cs" Inherits="Default2" %>
    
    Code (markup):
     
    Last edited: Oct 27, 2009
    wren, Oct 27, 2009 IP