当我从另一个项目复制一个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>
</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)
| 归档时间: |
|
| 查看次数: |
1569 次 |
| 最近记录: |