当网页从另一个项目复制aspx页面无法编译 [英] Aspx page doesn't compile when page is copied from another project
问题描述
我经常有编译错误的一个问题,当我拷贝过来的背后从另一个项目文件中的一个aspx页面和code,看来当我创建另一页,并手动将内容工作,但如果我只是复制文件它惯于。我已经检查,以确保命名空间和引用都OK,但仍然没有任何意义。我得到的错误是:
错误txtUser'这个名字并不在目前的情况下存在
块引用>我只是想知道为什么。
有关如我复制了以下内容:
ASPX
<%@页面语言=C#AutoEventWireup =真codeBehind =Login.aspx.cs继承=登录%GT;!< DOCTYPE HTML PUBLIC - // W3C // DTD XHTML 1.0过渡// ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
< HTML的xmlns =http://www.w3.org/1999/xhtml>
<头=服务器>
<标题>登录和LT; /标题>
< /头>
<身体GT;
<表ID =form1的=服务器>
<表ALIGN =中心WIDTH =300像素的风格=的margin-top:为200px;>
&所述; TR>
&所述; TD>
<传奇>登录和LT; /传说>
<表样式=WIDTH:30%; ALIGN =中心>
&所述; TR>
&所述; TD>
< ASP:文本框ID =txtUser=服务器>< / ASP:文本框>
< / TD>
< / TR>
&所述; TR>
&所述; TD>
&安培; NBSP;
< / TD>
< / TR>
< /表>
< / TD>
< / TR>
< /表>
< /表及GT;
< /身体GT;
< / HTML>ASPX.cs:
使用系统;
使用System.Collections.Generic;
使用System.Linq的;
使用的System.Web;
使用System.Web.UI程序;
使用System.Web.UI.WebControls;
使用System.Web.Security;公共部分类登录:System.Web.UI.Page
{
保护无效的Page_Load(对象发件人,EventArgs的发送)
{
txtUser.Text =文本;
}
}
解决方案这可能是因为设计师文件丢失的页面。如果是,你可以通过右键单击该页面在Solution Explorer中,选择转换为Web应用程序手动创建它。
I often have an issue with compile errors when I copy over an aspx page and code behind file from another project, it seems to work when I create another page and the content manually but if I just copy the files it won't. I have checked to make sure namespaces and references are ok but still doesn't make any sense. The error I get is:
Error The name 'txtUser' does not exist in the current context
I just wanted to understand why.
For e.g. I copied over the following:
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>
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"; } }
解决方案This is probably because the designer file is missing for the page. If it is, you can create it manually by right-clicking the page in the solution explorer and selecting 'Convert to Web Application'.
这篇关于当网页从另一个项目复制aspx页面无法编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!