CS0103 名称 'txtname' 在当前上下文中不存在
CS0103 the name 'txtname' does not exist in the current context
我得到 'txtname'、'txthours'、'txtrate',并且 'textgrosspay' 在当前上下文中不存在。错误代码是 CS0103。我也将设计师的文本框中的文字与这些文字进行了匹配。任何帮助表示赞赏。
这张图片显示了我的网络表单的设计部分:
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Grosspayapp : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Compute_Click(object sender, EventArgs e)
{
String name;
String shours, srate;
int hours;
double rate, grosspay;
name = txtname.Text;
shours = txthours.Text;
hours = Convert.ToInt32(shours);
srate = txtrate.Text;
rate = Convert.ToDouble(srate);
grosspay = hours * rate;
txtgrosspay.Text = grosspay.ToString();
}
}
源代码是
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Grosspayapp.aspx.cs" Inherits="GrossPayApp3_20.GrossPayProgram" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1 {
font-size: xx-large;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<span class="auto-style1"> Gross Pay Application </span>
<br />
</div>
<p>
</p>
<p>
</p>
<p>
Name
<asp:TextBox ID="txtname" runat="server"></asp:TextBox>
</p>
<p>
Hours
<asp:TextBox ID="txthours" runat="server"></asp:TextBox>
</p>
<p>
Rate
<asp:TextBox ID="txtrate" runat="server"></asp:TextBox>
</p>
<p>
<asp:Button ID="cmdcompute" runat="server" OnClick="Compute_Click" Text="Compute Gross Pay" />
</p>
<p>
Gross Pay
<asp:TextBox ID="txtgrosspay" runat="server"></asp:TextBox>
</p>
</form>
</body>
</html>
<%@ Page
指令的属性 Inherits
应引用页面的 class 名称 Grosspayapp
,但您
Inherits="GrossPayApp3_20.GrossPayProgram"
我得到 'txtname'、'txthours'、'txtrate',并且 'textgrosspay' 在当前上下文中不存在。错误代码是 CS0103。我也将设计师的文本框中的文字与这些文字进行了匹配。任何帮助表示赞赏。
这张图片显示了我的网络表单的设计部分:
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Grosspayapp : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Compute_Click(object sender, EventArgs e)
{
String name;
String shours, srate;
int hours;
double rate, grosspay;
name = txtname.Text;
shours = txthours.Text;
hours = Convert.ToInt32(shours);
srate = txtrate.Text;
rate = Convert.ToDouble(srate);
grosspay = hours * rate;
txtgrosspay.Text = grosspay.ToString();
}
}
源代码是
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Grosspayapp.aspx.cs" Inherits="GrossPayApp3_20.GrossPayProgram" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1 {
font-size: xx-large;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<span class="auto-style1"> Gross Pay Application </span>
<br />
</div>
<p>
</p>
<p>
</p>
<p>
Name
<asp:TextBox ID="txtname" runat="server"></asp:TextBox>
</p>
<p>
Hours
<asp:TextBox ID="txthours" runat="server"></asp:TextBox>
</p>
<p>
Rate
<asp:TextBox ID="txtrate" runat="server"></asp:TextBox>
</p>
<p>
<asp:Button ID="cmdcompute" runat="server" OnClick="Compute_Click" Text="Compute Gross Pay" />
</p>
<p>
Gross Pay
<asp:TextBox ID="txtgrosspay" runat="server"></asp:TextBox>
</p>
</form>
</body>
</html>
<%@ Page
指令的属性 Inherits
应引用页面的 class 名称 Grosspayapp
,但您
Inherits="GrossPayApp3_20.GrossPayProgram"