找回密码
 会员注册
查看: 200|回复: 0

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

[复制链接]

250

主题

1

回帖

819

积分

管理员

积分
819
发表于 2024-2-29 08:34:59 | 显示全部楼层 |阅读模式

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

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

  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Register.aspx.cs" Inherits="Web.Register" %>
  2. <!DOCTYPE html>
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head runat="server">
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  6. <title>用户注册</title>
  7. </head>
  8. <body>
  9.          
  10. <asp:Label ID="Label1" runat="server" Text="用户注册"></asp:Label>
  11. <form id="form1" runat="server">
  12. <div>
  13.         
  14. <br />
  15. <br />
  16. </div>
  17. 用户名:<asp:TextBox ID="TextBoxName" runat="server"></asp:TextBox>
  18. <br />
  19. <br />
  20.  密码: <asp:TextBox ID="TextBoxPassword" runat="server" TextMode="Password"></asp:TextBox>
  21. <br />
  22. <br />
  23. <br />
  24.  性别:<br />
  25. <asp:RadioButtonList ID="RadioButtonListSex" runat="server" RepeatDirection="Horizontal">
  26. <asp:ListItem Value="male">男</asp:ListItem>
  27. <asp:ListItem Value="female">女</asp:ListItem>
  28. </asp:RadioButtonList>
  29. <br />
  30. <br />
  31. 职业:<br />
  32. <asp:RadioButtonList ID="RadioButtonListWork" runat="server" RepeatDirection="Horizontal">
  33. <asp:ListItem Value="publicServat">公务员</asp:ListItem>
  34. <asp:ListItem Value="doctor">医务工作者</asp:ListItem>
  35. <asp:ListItem Value="teacher">教师</asp:ListItem>
  36. <asp:ListItem Value="business">经商</asp:ListItem>
  37. </asp:RadioButtonList>
  38. <br />
  39. 所属省份:<asp:DropDownList ID="DropDownListProvince" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownListProvince_SelectedIndexChanged" style="height: 19px">
  40. <asp:ListItem Value="guangdong">广东省</asp:ListItem>
  41. <asp:ListItem Value="guangxi">广西省</asp:ListItem>
  42. <asp:ListItem Value="heilongjiang">黑龙江省</asp:ListItem>
  43. </asp:DropDownList>
  44. <br />
  45. <br />
  46. 所在城市:<asp:ListBox ID="ListBoxCity" runat="server" Height="43px" style="margin-top: 4px" Width="102px"></asp:ListBox>
  47. <br />
  48. <br />
  49. 爱好:<asp:CheckBoxList ID="CheckBoxListHobby" runat="server" RepeatColumns="2">
  50. <asp:ListItem>球类运动</asp:ListItem>
  51. <asp:ListItem>田径运动</asp:ListItem>
  52. <asp:ListItem>读书看报</asp:ListItem>
  53. <asp:ListItem>聊天交友</asp:ListItem>
  54. </asp:CheckBoxList>
  55. <br />
  56.        
  57. <asp:Button ID="ButtonOk" runat="server" OnClick="ButtonOk_Click" Text="确定" />
  58. <br />
  59. </form>
  60. </body>
  61. </html>
复制代码



二:后台处理代码(C#实现 .aspx.cs)

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. namespace Web
  8. {
  9. public partial class Register : System.Web.UI.Page
  10. {
  11. protected void Page_Load(object sender, EventArgs e)
  12. {
  13. }
  14. protected void DropDownListProvince_SelectedIndexChanged(object sender, EventArgs e)
  15. {
  16. switch (DropDownListProvince.SelectedItem.Text)
  17. {
  18. case "广东省":
  19. ListBoxCity.Items.Clear();
  20. ListBoxCity.Items.Add("广州市");
  21. ListBoxCity.Items.Add("深圳市");
  22. break;
  23. case "广西省":
  24. ListBoxCity.Items.Clear();
  25. ListBoxCity.Items.Add("南宁市");
  26. ListBoxCity.Items.Add("桂林市");
  27. break;
  28. case "黑龙江省":
  29. ListBoxCity.Items.Clear();
  30. ListBoxCity.Items.Add("哈尔滨市");
  31. ListBoxCity.Items.Add("齐齐哈尔市");
  32. break;
  33. }
  34. }
  35. protected void ButtonOk_Click(object sender, EventArgs e)
  36. {
  37. string name, password, sex = " ", work, location = "", hobby = "";
  38. if (TextBoxName.Text == "")
  39. {
  40. Response.Write("<script>window.alert('用户名不能为空!');</script>");
  41. }
  42. else
  43. {
  44. name = TextBoxName.Text;
  45. password = TextBoxPassword.Text;
  46. if (RadioButtonListSex.Items[0].Selected)
  47. {
  48. sex = "男";
  49. }
  50. else if (RadioButtonListSex.Items[1].Selected)
  51. {
  52. sex = "女";
  53. }
  54. work = RadioButtonListWork.SelectedItem.Text;
  55. if (ListBoxCity.SelectedItem != null)
  56. {
  57. location = DropDownListProvince.SelectedItem.Text + "," + ListBoxCity.SelectedItem.Text;
  58. }
  59. for (int i = 0; i < CheckBoxListHobby.Items.Count; i++)
  60. {
  61. if (CheckBoxListHobby.Items[i].Selected)
  62. hobby += CheckBoxListHobby.Items[i].Text + ",";
  63. }
  64. hobby = hobby.TrimEnd(',');
  65. Response.Redirect(string.Format("SimpleResult.aspx?name={0}&sex={1}&work={2}&location={3}&hobby={4}", name, sex, work, location, hobby));
  66. }
  67. }
  68. }
  69. }
复制代码



三:结果界面代码( .aspx文件)


  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SimpleResult.aspx.cs" Inherits="Web.SimpleResult" %>
  2. <!DOCTYPE html>
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head runat="server">
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  6. <title>注册信息</title>
  7. </head>
  8. <body>
  9. <form id="form1" runat="server">
  10. <div>
  11. 您注册的信息是:<br />
  12. 姓 名:<%=name %><br />
  13. 性 别:<%=sex %><br />
  14. 职 业:<%=work %><br />
  15. 所在城市:<%=location %><br />
  16. 爱 好:<%=hobby %><br />
  17. 请牢记你的密码!
  18. </div>
  19. </form>
  20. </body>
  21. </html>
复制代码



四:结果页面代码 (.aspx.cs文件)

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. namespace Web
  8. {
  9. public partial class SimpleResult : System.Web.UI.Page
  10. {
  11. public string name;
  12. public string sex;
  13. public string work;
  14. public string location;
  15. public string hobby;
  16. protected void Page_Load(object sender, EventArgs e)
  17. {
  18. name = Request.QueryString["name"];
  19. sex = Request.QueryString["sex"];
  20. work = Request.QueryString["work"];
  21. location = Request.QueryString["location"];
  22. hobby = Request.QueryString["hobby"];
  23. }
  24. }
  25. }
复制代码



来源:https://blog.csdn.net/dearKundy/article/details/53538312
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 会员注册

本版积分规则

QQ|手机版|心飞设计-版权所有:微度网络信息技术服务中心 ( 鲁ICP备17032091号-12 )|网站地图

GMT+8, 2024-12-26 12:33 , Processed in 2.048131 second(s), 26 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表