【问题标题】:CS0103 the name 'txtname' does not exist in the current contextCS0103 当前上下文中不存在名称“txtname”
【发布时间】: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">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Gross Pay Application </span>
            <br />
        </div>
        <p>
            &nbsp;</p>
        <p>
            &nbsp;</p>
        <p>
            Name&nbsp;&nbsp;&nbsp;
            <asp:TextBox ID="txtname" runat="server"></asp:TextBox>
        </p>
        <p>
            Hours&nbsp;&nbsp;&nbsp;
            <asp:TextBox ID="txthours" runat="server"></asp:TextBox>
        </p>
        <p>
            Rate&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <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&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:TextBox ID="txtgrosspay" runat="server"></asp:TextBox>
        </p>
    </form>
</body>
</html>

【问题讨论】:

  • 你应该显示你的.aspx的来源,而不仅仅是设计师的截图。
  • 刚刚添加了源代码,谢谢。
  • &lt;% @Page %&gt; 指令在哪里?
  • 对不起,我把它隔开,现在它显示了指令。
  • 你有“Grosspayapp.designer.cs”文件吗?

标签: c# asp.net webforms


【解决方案1】:

&lt;%@ Page 指令的属性Inherits 应该引用页面的类名Grosspayapp,但你有

Inherits="GrossPayApp3_20.GrossPayProgram"

【讨论】:

  • 感谢您修复了我的错误,现在我的程序正在运行。
猜你喜欢
  • 2021-10-31
  • 2017-03-01
  • 2015-09-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多