ASP.NET菜鸟之路之Response小例子
背景
我是一个ASP.NET菜鸟,暂时开始学习ASP.NET,在此记录下我个人敲的代码,没有多少参考价值,请看到的盆友们为我点个赞支持我一下,多谢了。
Response.Write Redirect
<form id="form1" runat="server"> <div> <table> <tr> <td >用户名:</td> <td><asp:TextBox runat="server" ID="txtName"/></td> </tr> <tr> <td >性别:</td> <td ><asp:TextBox runat="server" ID="txtSex"/></td> </tr> <tr> <td> </td> <td><asp:Button runat="server" ID="btnRegister" Text="注册" OnClick="btnRegister_Click" /></td> </tr> </table> </div> </form>
Redirect.aspx.cs文件里添加一个btnRegister_Click事件
protected void btnRegister_Click(object sender, EventArgs e) { string strname = this.txtName.Text; string sex = ""; if (txtSex.Text == "男") { sex = "先生"; } else if (txtSex.Text == "女") { sex = "女士"; } Response.Redirect("Index.aspx?sName=" + strname + "&Sex=" + sex); }
然后新建一个wen窗体Index.aspx,在后台这样写
protected void Page_Load(object sender, EventArgs e) { string name = Request.QueryString["sName"]; string sex = Request.QueryString["Sex"]; Response.Write(name + " " + sex +"欢迎注册"); }