用户注册页面
为了网络中心的招聘,开始学习asp.net了,和前面学的网页制作完全两个概念,感觉自己悟性还是有点弱(笨?)
几天为网络中心第三次考核第一天,十五天小组开发个网站,全部都是用新知识开发,昨晚布置了一晚开发工具,见天看了一天asp.net,,从下午开始上机写代码,到现在,第一个程序基本理解了,路漫漫其修远兮,任重道远,努力!
进程有点慢,希望以后可以快点,我在这次项目分工里为数据库设计,看似简单实则不易,并且是整个项目的核心,我会好好完成的。
纪念第一次的接触.net,发表见天做的注册页面如下:
前台代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication4.WebForm1" %>
<!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>changxing
</title>
<link href="/style/site.css" rel="stylesheet" type="text/css" />
<style type="text/css">
#Radio2
{
width: 19px;
}
</style>
</head>
<body >
<form id="form1" runat="server">
<div id = "header">
 
用户注册</div>
<div>
我的第一个asp.net网页</div>
<p>
用户名:
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</p>
<p>
密 码 :<asp:TextBox
ID="TextBox2" runat="server" TextMode="Password"></asp:TextBox>
</p>
<asp:Panel ID="Panel1" runat="server" Width="1018px">
性别:<asp:RadioButton ID="RadioButton2" runat="server"
GroupName="sexy" Text="男" />
<asp:RadioButton ID="RadioButton3" runat="server" GroupName="sexy" Text="女" />
<asp:Panel ID="Panel2" runat="server" style="margin-top: 0px" Width="1016px">
职业:<asp:RadioButtonList ID="RadioButtonList1" runat="server"
AutoPostBack="True" BorderStyle="Solid" RepeatLayout="Flow" Width="266px">
<asp:ListItem>老师</asp:ListItem>
<asp:ListItem>医生</asp:ListItem>
<asp:ListItem Selected="True">程序员</asp:ListItem>
</asp:RadioButtonList>
<br />
</asp:Panel>
</asp:Panel>
<p>
所属省份:<asp:DropDownList
ID="DropDownList1" runat="server" AutoPostBack="True" BackColor="Yellow"
ForeColor="Blue" Height="29px" style="margin-left: 0px" Width="124px"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem>北京</asp:ListItem>
<asp:ListItem>河南省</asp:ListItem>
//asp中大部分的添加方法如,checkbox ,checkboxlist等
<asp:ListItem>山东省</asp:ListItem>
</asp:DropDownList>
</p>
<p>
所在城市: <asp:ListBox
ID="ListBox1" runat="server" Height="61px" style="margin-top: 10px"
Width="206px"></asp:ListBox>
</p>
<p>
</p>
<p>
</p>
<p>
<asp:Button
ID="Button2" runat="server" onclick="Button2_Click" Text="Button" />
<input id="Reset1" type="reset" value="reset" /></p>
<p>
</p>
</form>
</body>
</html>
后台代码(c#):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
namespace WebApplication4
{
public partial class WebForm1 : System.Web.UI.Page
{
public WebForm1()
{
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
switch (DropDownList1.SelectedItem.Text)
{
case "河南省":
ListBox1.Items.Clear();
ListBox1.Items.Add("林州");
ListBox1.Items.Add("开封");
break;
case "北京":
ListBox1.Items.Clear();
ListBox1.Items.Add("天俺们");
ListBox1.Items.Add("长城");
break;
case "浙江":
ListBox1.Items.Clear();
ListBox1.Items.Add("青岛");
ListBox1.Items.Add("济南");
break;
}
}
protected void Button2_Click(object sender, EventArgs e)
{
string name, password, sex, work, location = "";
if (TextBox1.Text == "")
{
Response.Write("<script>window.alert('用户名不能空!');</script>");
}
else
{
name = TextBox1.Text;
password = TextBox2.Text;
if (RadioButton2.Checked)
{
sex = "男";
}
else
{
sex = "女";
}
work = RadioButtonList1.SelectedItem.Text;
if (ListBox1.SelectedItem != null)
{
location = DropDownList1.SelectedItem.Text + "," + ListBox1.SelectedItem.Text;
}
Response.Redirect(string.Format("simpleresult.aspx?name={0}&sex={1}&work={2}&location={3}&password={4}",name,sex,work,location,password));
//不能空格
}
}
}
}