|
我们利用ASP.NET来实现简单的注册界面
一:注册首页的界面代码(.aspx文件 这里使用的是asp自带的控件,也可以使用HTML的控件来实现)
- <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Register.aspx.cs" Inherits="Web.Register" %>
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
- <title>用户注册</title>
- </head>
- <body>
-
- <asp:Label ID="Label1" runat="server" Text="用户注册"></asp:Label>
- <form id="form1" runat="server">
- <div>
-
- <br />
- <br />
- </div>
- 用户名:<asp:TextBox ID="TextBoxName" runat="server"></asp:TextBox>
- <br />
- <br />
- 密码: <asp:TextBox ID="TextBoxPassword" runat="server" TextMode="Password"></asp:TextBox>
- <br />
- <br />
- <br />
- 性别:<br />
- <asp:RadioButtonList ID="RadioButtonListSex" runat="server" RepeatDirection="Horizontal">
- <asp:ListItem Value="male">男</asp:ListItem>
- <asp:ListItem Value="female">女</asp:ListItem>
- </asp:RadioButtonList>
- <br />
- <br />
- 职业:<br />
- <asp:RadioButtonList ID="RadioButtonListWork" runat="server" RepeatDirection="Horizontal">
- <asp:ListItem Value="publicServat">公务员</asp:ListItem>
- <asp:ListItem Value="doctor">医务工作者</asp:ListItem>
- <asp:ListItem Value="teacher">教师</asp:ListItem>
- <asp:ListItem Value="business">经商</asp:ListItem>
- </asp:RadioButtonList>
- <br />
- 所属省份:<asp:DropDownList ID="DropDownListProvince" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownListProvince_SelectedIndexChanged" style="height: 19px">
- <asp:ListItem Value="guangdong">广东省</asp:ListItem>
- <asp:ListItem Value="guangxi">广西省</asp:ListItem>
- <asp:ListItem Value="heilongjiang">黑龙江省</asp:ListItem>
- </asp:DropDownList>
- <br />
- <br />
- 所在城市:<asp:ListBox ID="ListBoxCity" runat="server" Height="43px" style="margin-top: 4px" Width="102px"></asp:ListBox>
- <br />
- <br />
- 爱好:<asp:CheckBoxList ID="CheckBoxListHobby" runat="server" RepeatColumns="2">
- <asp:ListItem>球类运动</asp:ListItem>
- <asp:ListItem>田径运动</asp:ListItem>
- <asp:ListItem>读书看报</asp:ListItem>
- <asp:ListItem>聊天交友</asp:ListItem>
- </asp:CheckBoxList>
- <br />
-
- <asp:Button ID="ButtonOk" runat="server" OnClick="ButtonOk_Click" Text="确定" />
- <br />
- </form>
- </body>
- </html>
复制代码
二:后台处理代码(C#实现 .aspx.cs)
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- namespace Web
- {
- public partial class Register : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- protected void DropDownListProvince_SelectedIndexChanged(object sender, EventArgs e)
- {
- switch (DropDownListProvince.SelectedItem.Text)
- {
- case "广东省":
- ListBoxCity.Items.Clear();
- ListBoxCity.Items.Add("广州市");
- ListBoxCity.Items.Add("深圳市");
- break;
- case "广西省":
- ListBoxCity.Items.Clear();
- ListBoxCity.Items.Add("南宁市");
- ListBoxCity.Items.Add("桂林市");
- break;
- case "黑龙江省":
- ListBoxCity.Items.Clear();
- ListBoxCity.Items.Add("哈尔滨市");
- ListBoxCity.Items.Add("齐齐哈尔市");
- break;
- }
- }
- protected void ButtonOk_Click(object sender, EventArgs e)
- {
- string name, password, sex = " ", work, location = "", hobby = "";
- if (TextBoxName.Text == "")
- {
- Response.Write("<script>window.alert('用户名不能为空!');</script>");
- }
- else
- {
- name = TextBoxName.Text;
- password = TextBoxPassword.Text;
- if (RadioButtonListSex.Items[0].Selected)
- {
- sex = "男";
- }
- else if (RadioButtonListSex.Items[1].Selected)
- {
- sex = "女";
- }
- work = RadioButtonListWork.SelectedItem.Text;
- if (ListBoxCity.SelectedItem != null)
- {
- location = DropDownListProvince.SelectedItem.Text + "," + ListBoxCity.SelectedItem.Text;
- }
- for (int i = 0; i < CheckBoxListHobby.Items.Count; i++)
- {
- if (CheckBoxListHobby.Items[i].Selected)
- hobby += CheckBoxListHobby.Items[i].Text + ",";
- }
- hobby = hobby.TrimEnd(',');
- Response.Redirect(string.Format("SimpleResult.aspx?name={0}&sex={1}&work={2}&location={3}&hobby={4}", name, sex, work, location, hobby));
- }
- }
- }
- }
复制代码
三:结果界面代码( .aspx文件)
- <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SimpleResult.aspx.cs" Inherits="Web.SimpleResult" %>
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
- <title>注册信息</title>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- 您注册的信息是:<br />
- 姓 名:<%=name %><br />
- 性 别:<%=sex %><br />
- 职 业:<%=work %><br />
- 所在城市:<%=location %><br />
- 爱 好:<%=hobby %><br />
- 请牢记你的密码!
- </div>
- </form>
- </body>
- </html>
复制代码
四:结果页面代码 (.aspx.cs文件)
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- namespace Web
- {
- public partial class SimpleResult : System.Web.UI.Page
- {
- public string name;
- public string sex;
- public string work;
- public string location;
- public string hobby;
- protected void Page_Load(object sender, EventArgs e)
- {
- name = Request.QueryString["name"];
- sex = Request.QueryString["sex"];
- work = Request.QueryString["work"];
- location = Request.QueryString["location"];
- hobby = Request.QueryString["hobby"];
- }
- }
- }
复制代码
来源:https://blog.csdn.net/dearKundy/article/details/53538312 免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |
|