【发布时间】:2020-03-21 02:10:03
【问题描述】:
我得到“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>
【问题讨论】:
-
你应该显示你的
.aspx的来源,而不仅仅是设计师的截图。 -
刚刚添加了源代码,谢谢。
-
<% @Page %>指令在哪里? -
对不起,我把它隔开,现在它显示了指令。
-
你有“Grosspayapp.designer.cs”文件吗?