ASP.NET 实现简单的注册界面(使用asp控件)

我们利用ASP.NET来实现简单的注册界面

一:注册首页的界面代码(.aspx文件 这里使用的是asp自带的控件,也可以使用HTML的控件来实现)

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Register.aspx.cs" Inherits="Web.Register" %>








    用户注册


             
    
    
        

用户名:

 密码:


 性别:


职业:
公务员 医务工作者 教师 经商
所属省份: 广东省 广西省 黑龙江省

所在城市:

爱好: 球类运动 田径运动 读书看报 聊天交友
       



二:后台处理代码(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("");
            }
            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" %>








    注册信息


    
您注册的信息是:
姓 名:<%=name %>
性 别:<%=sex %>
职 业:<%=work %>
所在城市:<%=location %>
爱 好:<%=hobby %>
请牢记你的密码!



四:结果页面代码 (.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"];
        }
    }
}


你可能感兴趣的:(C#)