问题
In the source code for a VB ASP.NET website that I'm trying to get compiling, I've got a couple of "The file 'bla.aspx.vb' does not exist" errors; there is a corresponding .aspx file, but it's missing its companion .aspx.vb code-behind file.
The error msg displays because of this in the .aspx file:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Bla.aspx.vb" Inherits="cms_ShowEscalatorRule" %>
To just get the project compiling (this is just for running the project locally, the code I change won't affect the production code), would it be preferable to:
0) Comment out that section entirely
1) Remove the "CodeFile="Bla.aspx.vb" portion
2) Add a code-behind file
If the last option is best, what needs to be in it for a minimal amount of code - just enough to prevent the "missing file" error?
It's rather macabre to me that there is no contextual menu item for .aspx files that allows a minimal corresponding .aspx.vb to be created.
回答1:
You may have to have a file because the .aspx may have references (and you will have to recreate those in the code-behind) to items from the code-behind file.
The minimum that's needed is a class inheriting from Page:
public class Bla : System.Web.UI.Page
{
}
This - of course - is not mandatory - you may as well use the alternative approach and inline the code-behind in a server-side script block in the .aspx file. Former approach however is much neater.
回答2:
G. Stoynev basically had what I needed, but since this is VB, I had to change it to:
Public Class Bla
Inherits System.Web.UI.Page
End Class
I have never used VB before, so I used this to make the translation.
来源:https://stackoverflow.com/questions/36223044/what-is-the-preferred-workaround-when-an-aspx-files-code-behind-file-is-missin