C# WebForm1不包含';上下文';
我是C#的新手。下面是Kudvenkat教程中的简单示例。 不断地犯错误,却无法理解我做错了什么 My.aspx文件:C# WebForm1不包含';上下文';,c#,asp.net,ado.net,C#,Asp.net,Ado.net,我是C#的新手。下面是Kudvenkat教程中的简单示例。 不断地犯错误,却无法理解我做错了什么 My.aspx文件: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="WebForm1.aspx.cs" Inherits="WebForm1"%> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="WebForm1.aspx.cs" Inherits="WebForm1"%>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<table style="border: 1px solid black; font-family:Arial">
<tr>
<td>
Employee Name
</td>
<td>
<asp:TextBox ID="txtEmployeeName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Gender
</td>
<td>
<asp:DropDownList ID="ddlGender" runat="server">
<asp:ListItem>Male</asp:ListItem>
<asp:ListItem>Female</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
Salary
</td>
<td>
<asp:TextBox ID="txtSalary" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="btnSubmit" runat="server" Text="Submit" onclick="btnSubmit_Click" />
</td>
</tr>
<tr>
<td colspan="2">
<asp:Label ID="lblMessage" runat="server"></asp:Label>
</td>
</tr>
</table>
</form>
</body>
</html>
和我的aspx.designer.cs文件:
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace adoDemo {
public partial class WebForm1 {
/// <summary>
/// form1 control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.HtmlControls.HtmlForm form1;
/// <summary>
/// txtEmployeeName control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.TextBox txtEmployeeName;
/// <summary>
/// ddlGender control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.DropDownList ddlGender;
/// <summary>
/// txtSalary control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.TextBox txtSalary;
/// <summary>
/// btnSubmit control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Button btnSubmit;
/// <summary>
/// lblMessage control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Label lblMessage;
}
}
//------------------------------------------------------------------------------
//
//这段代码是由一个工具生成的。
//
//对此文件的更改可能会导致不正确的行为,如果
//重新生成代码。
//
//------------------------------------------------------------------------------
名称空间adoDemo{
公共部分类WebForm1{
///
///form1控件。
///
///
///自动生成的字段。
///将字段声明从设计器文件修改为代码隐藏文件。
///
受保护的全局::System.Web.UI.HtmlControls.HtmlForm form1;
///
///txtEmployeeName控件。
///
///
///自动生成的字段。
///将字段声明从设计器文件修改为代码隐藏文件。
///
受保护的全局::System.Web.UI.WebControls.TextBox txtEmployeeName;
///
///性别控制。
///
///
///自动生成的字段。
///将字段声明从设计器文件修改为代码隐藏文件。
///
受保护的全局::System.Web.UI.WebControls.DropDownList;
///
///TXT薪酬控制。
///
///
///自动生成的字段。
///将字段声明从设计器文件修改为代码隐藏文件。
///
受保护的全局::System.Web.UI.WebControls.TextBox txtSalary;
///
///btnSubmit控件。
///
///
///自动生成的字段。
///将字段声明从设计器文件修改为代码隐藏文件。
///
受保护的全局::System.Web.UI.WebControls.Button btnsupmit;
///
///LBL消息控制。
///
///
///自动生成的字段。
///将字段声明从设计器文件修改为代码隐藏文件。
///
受保护的全局::System.Web.UI.WebControls.Label lblMessage;
}
}
由于和程序集缓存问题,您可能会遇到此错误,因为VS对实际需要重新编译的内容感到困惑。正常重新编译
查看设计器文件,看看VisualStudio是否在其中为控件创建了一个条目。确保您没有其他具有类似声明的文件
很多时候,解决这个问题的最佳方法是删除、重新创建和重新命名表单。因为,我们不应该自己编辑设计器文件。由于和程序集缓存问题,您可能会遇到此错误,因为VS对实际需要重新编译的内容感到困惑。正常重新编译 查看设计器文件,看看VisualStudio是否在其中为控件创建了一个条目。确保您没有其他具有类似声明的文件
很多时候,解决这个问题的最佳方法是删除、重新创建和重新命名表单。因为,我们不应该自己编辑设计器文件。问题在于这一行
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="WebForm1.aspx.cs" Inherits="WebForm1"%>
应该是
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="WebForm1.aspx.cs" Inherits="adoDemo.WebForm1"%>
Inherits
还应包含名称空间
名称,在您的情况下adoDemo
问题在于这一行
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="WebForm1.aspx.cs" Inherits="WebForm1"%>
应该是
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="WebForm1.aspx.cs" Inherits="adoDemo.WebForm1"%>
Inherits
还应包含命名空间
名称,在您的情况下adoDemo
检查设计器文件以查看是否生成了属性,如果没有,请删除并重新创建此文本框我已添加设计器文件。很抱歉,但是我如何才能看到是否生成了属性?它实际上在那里,只需重新创建干净的属性,然后再次尝试检查设计器文件以查看是否生成了属性,如果没有,请删除并重新创建此TextBox我已添加了设计器文件。很抱歉,但是我如何才能看到是否生成了属性?它实际上在那里,只需重新创建干净的属性,然后再次尝试重新创建并重命名表单。我还清除了VS缓存目录。但它仍然带下划线:txtEmployeeName.Text、ddlGender.SelectedValue和“txtSalary.Text”有红色下划线,表示“name.txt在当前上下文中不存在”。我开始讨厌这种语言:)非常感谢。帮助我的是完全删除并重新创建整个项目,并重命名每个可能的文件。非常感谢你!!!我重新创建并重命名了表单。我还清除了VS缓存目录。但它仍然带下划线:txtEmployeeName.Text、ddlGender.SelectedValue和“txtSalary.Text”有红色下划线,表示“name.txt在当前上下文中不存在”。我开始讨厌这种语言:)非常感谢。帮助我的是完全删除并重新创建整个项目,并重命名每个可能的文件。非常感谢你!!!