weixin_39087345 2021-08-15 15:44 采纳率: 100%
浏览 115
已结题

(悬赏20元,急)使用VS 2010开发asp.net/C#,但提示 错误 "_Default"不包含"txtName"的定义,该怎么处理

(悬赏20元)使用VS 2010开发asp.net/C#,但提示 错误 "_Default"不包含"txtName"的定义,该怎么处理

img

Default.aspx代码如下:

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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>页面跳转并传递参数</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table style="font-size: 9pt">
            <tr>
                <td style="width: 61px">
                    姓名:</td>
                <td style="width: 100px">
                    <asp:TextBox ID="txtName" runat="server"></asp:TextBox></td>
            </tr>
            <tr>
                <td style="width: 61px">
                    性别:</td>
                <td style="width: 100px">
                    <asp:RadioButton ID="rbtnSex1" runat="server" Checked="True" Text="男" GroupName="Sex" />
                    <asp:RadioButton ID="rbtnSex2" runat="server" Text="女" GroupName="Sex" /></td>
            </tr>
            <tr>
                <td style="width: 61px">
                </td>
                <td style="width: 100px">
                    <asp:Button ID="btnOK" runat="server" OnClick="btnOK_Click" Text="确定" /></td>
            </tr>
        </table>
    
    </div>
    </form>
</body>
</html>

Default.aspx.cs代码如下:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnOK_Click(object sender, EventArgs e)
    {
        string name=this.txtName.Text;
        string sex="先生";
        if(rbtnSex2 .Checked)
            sex="女士";
        Response.Redirect("~/welcome.aspx?Name="+name+"&Sex="+sex);
    }
}

welcome.aspx代码如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="welcome.aspx.cs" Inherits="welcome" %>

<!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>Welcome页</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        &nbsp;</div>
    </form>
</body>
</html>

welcome.aspx.cs代码如下:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class welcome : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string name = Request.Params["Name"];
        string sex = Request.Params["Sex"];
        Response.Write("欢迎"+name+sex+"!");
    }
   
}


img

  • 写回答

2条回答 默认 最新

  • CSDN专家-showbo 2021-08-16 11:07
    关注

    CodeFile改CodeBehind试试。

    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
    
    ======>
    
    <%@ Page Language="C#" AutoEventWireup="true"  CodeBehind="Default.aspx.cs" Inherits="_Default" %>
    CodeBehind
    

    如果还是不行,改成无codeilfe模式的,就是新建aspx页面取消勾选将代码放到单独文件中,aspx直接内嵌代码

    img

    
    <%@ Page Language="C#"  %>
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
        }
        protected void btnOK_Click(object sender, EventArgs e)
        {
            string name=this.txtName.Text;
            string sex="先生";
            if(rbtnSex2 .Checked)
                sex="女士";
            Response.Redirect("~/welcome.aspx?Name="+name+"&Sex="+sex);
        }
    </script>
    <!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>页面跳转并传递参数</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <table style="font-size: 9pt">
                <tr>
                    <td style="width: 61px">
                        姓名:</td>
                    <td style="width: 100px">
                        <asp:TextBox ID="txtName" runat="server"></asp:TextBox></td>
                </tr>
                <tr>
                    <td style="width: 61px">
                        性别:</td>
                    <td style="width: 100px">
                        <asp:RadioButton ID="rbtnSex1" runat="server" Checked="True" Text="男" GroupName="Sex" />
                        <asp:RadioButton ID="rbtnSex2" runat="server" Text="女" GroupName="Sex" /></td>
                </tr>
                <tr>
                    <td style="width: 61px">
                    </td>
                    <td style="width: 100px">
                        <asp:Button ID="btnOK" runat="server" OnClick="btnOK_Click" Text="确定" /></td>
                </tr>
            </table>
        </div>
        </form>
    </body>
    </html>
    
    
    

    vs2019按照你的代码建立aspx和cs文件没问题。之前碰到一个也是用2010开发导入别人的项目,运行没问题,但是vs就是提示无法找到控件。。不知道那里配置出问题了。。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
    1人已打赏
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 8月24日
  • 已采纳回答 8月16日
  • 修改了问题 8月16日
  • 修改了问题 8月16日
  • 展开全部

悬赏问题

  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行