Create code behind file after aspx has been created

前端 未结 5 518
有刺的猬
有刺的猬 2021-02-01 16:57

I just inherited a web site that was created by a designer. The site was originally created with all *.html files. The designer renamed all the *.html files to *.aspx files.

5条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-01 17:21

    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.

提交回复
热议问题