(悬赏20元)使用VS 2010开发asp.net/C#,但提示 错误 "_Default"不包含"txtName"的定义,该怎么处理
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>
</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+"!");
}
}