从其他项目复制页面时,Aspx页面无法编译

Rub*_*ans 2 asp.net

当我从另一个项目复制一个aspx页面和代码隐藏文件时,我常常遇到编译错误的问题,当我手动创建另一个页面和内容时它似乎有效,但如果我只复制文件则不会.我已经检查过以确保命名空间和引用是正确的,但仍然没有任何意义.我得到的错误是:

错误当前上下文中不存在名称"txtUser"

我只想了解原因.

例如,我复制了以下内容:

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Login</title>
</head>
<body>
    <form id="form1" runat="server">
    <table align="center" width="300px" style="margin-top: 200px;">
        <tr>
            <td>
                    <legend>Login</legend>
                    <table style="width: 30%;" align="center">
                        <tr>
                            <td>
                                <asp:TextBox ID="txtUser" runat="server"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                &nbsp;
                            </td>
                        </tr>
                    </table>
            </td>
        </tr>
    </table>
    </form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

ASPX.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        txtUser.Text = "text";
    }
}
Run Code Online (Sandbox Code Playgroud)

pma*_*lee 5

这可能是因为页面缺少设计器文件.如果是,您可以通过右键单击解决方案资源管理器中的页面并选择"转换为Web应用程序"来手动创建它.