asp.net - 从另一个项目复制页面时,Aspx 页面无法编译

标签 asp.net

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

Error The name 'txtUser' does not exist in the current context

我只是想了解为什么。

例如我复制了以下内容:

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>

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";
    }
}

最佳答案

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

关于asp.net - 从另一个项目复制页面时,Aspx 页面无法编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2311071/

相关文章:

asp.net - 正则表达式匹配该月的前 28 天

asp.net - 根据登录状态,两个页面使用相同的 url

c# - 将数据表从一个 aspx 页面传输到另一个 C#

asp.net - 在非生产环境中复制与负载相关的崩溃

c# - 在Asp.net中获取两次之间的小时数

javascript - 如何从使用 javascript 动态添加的文本框获取值 - c#

c# - 对于 Int32 错误,值太大或太小

c# - 带参数登录 asp.net 重定向

通过 ASP.NET 连接 MySQL

c# - asp.net进度加载