ASp.net 注册
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %> <!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>
<style type="text/css"> .z {
width:600px;
margin-left:100px;
}
.t {
margin-left:100px;
} </style>
<body>
<form id="form1" runat="server">
<div style="border:1px solid black;" class="z">
<table border="0" class="t">
<tr>
<td><asp:Label ID="Label1" runat="server" Text="姓名:"></asp:Label></td>
<td> <asp:TextBox ID="name" runat="server" AutoPostBack="True"></asp:TextBox></td>
<td> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="姓名不能为空" ControlToValidate="name"></asp:RequiredFieldValidator></td>
</tr> <tr>
<td><asp:Label ID="Label2" runat="server" Text="密码"></asp:Label> </td>
<td><asp:TextBox ID="passwd" runat="server"></asp:TextBox> </td>
<td> <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="密码不能为空" ControlToValidate="passwd"></asp:RequiredFieldValidator> </td>
</tr> <tr>
<td><asp:Label ID="Label3" runat="server" Text="密码确认"></asp:Label> </td>
<td><asp:TextBox ID="repasswd" runat="server"></asp:TextBox> </td>
<td><asp:CompareValidator ID="CompareValidator1" runat="server" ErrorMessage="两次密码不一样" ControlToCompare="passwd" ControlToValidate="repasswd"></asp:CompareValidator> </td>
</tr> <tr> <td><asp:Label ID="Label4" runat="server" Text="Emial"></asp:Label> </td>
<td> <asp:TextBox ID="email" runat="server"></asp:TextBox> </td>
<td> <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ErrorMessage="Emial不能为空" ControlToValidate="email"></asp:RequiredFieldValidator> </td>
</tr>
<tr> <td><asp:Label ID="Label5" runat="server" Text="性别"></asp:Label> </td>
<td> <asp:RadioButton ID="RadioButton1" runat="server" Text="男" AutoPostBack="True" GroupName="rb" OnCheckedChanged="RadioButton1_CheckedChanged" /> <asp:RadioButton ID="RadioButton2" runat="server" Text="女" AutoPostBack="True" GroupName="rb" /> </td>
</tr>
<tr>
<td> <asp:Label ID="Label6" runat="server" Text="选择省份"></asp:Label> </td>
<td> <asp:DropDownList ID="addres" runat="server" Height="22px" Width="137px" AutoPostBack="True"></asp:DropDownList> </td>
<td><asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ErrorMessage="省份不能为空" ControlToValidate="addres"></asp:RequiredFieldValidator> </td> </tr>
<tr>
<td> <asp:Label ID="Label7" runat="server" Text="爱好"></asp:Label> </td> <td> <asp:CheckBoxList ID="CheckBoxList1" runat="server" RepeatColumns="5" AutoPostBack="True">
<asp:ListItem>体育</asp:ListItem>
<asp:ListItem>音乐</asp:ListItem>
<asp:ListItem>旅游</asp:ListItem>
<asp:ListItem>读书</asp:ListItem>
<asp:ListItem>游戏</asp:ListItem>
</asp:CheckBoxList> </td>
</tr>
<tr>
<td> <asp:Label ID="Label8" runat="server" Text="备注"></asp:Label> </td>
<td> <asp:TextBox ID="remark" runat="server" AutoPostBack="True" Width="255px" Height="76px" TextMode="MultiLine"></asp:TextBox> </td>
<td> <asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server" ErrorMessage="备注为空" ControlToValidate="remark"></asp:RequiredFieldValidator> </td> </tr>
<tr>
<td> <asp:Label ID="Label9" runat="server" Text="上传照片"></asp:Label> </td>
<td> <asp:FileUpload ID="FileUpload1" runat="server" Width="249px" /> </td>
<td> <asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server" ErrorMessage="文件上传为空" ControlToValidate="FileUpload1"></asp:RequiredFieldValidator> </td>
</tr>
<tr> <td> <asp:Button ID="Button1" runat="server" Text="注册" OnClick="Button1_Click" /> </td>
</tr> </table> <style type="text/css">
.xx {
color:red;
padding:10px;
border-top:1px solid black; }
.xx p {
margin-left:90px;
} </style>
<div class="xx" runat="server">
<p><asp:Label ID="Label10" runat="server" Text="您的姓名为:"></asp:Label><asp:Label ID="lname" runat="server" Text="Label"></asp:Label></p>
<p><asp:Label ID="Label12" runat="server" Text="您的密码为:"></asp:Label><asp:Label ID="lpasswd" runat="server" Text="Label"></asp:Label></p>
<p><asp:Label ID="Label14" runat="server" Text="您的Email为:"></asp:Label><asp:Label ID="lemail" runat="server" Text="Label"></asp:Label></p>
<p><asp:Label ID="Label16" runat="server" Text="您的性别为:"></asp:Label><asp:Label ID="lsex" runat="server" Text="Label"></asp:Label></p>
<p><asp:Label ID="Label18" runat="server" Text="您的籍贯为:"></asp:Label><asp:Label ID="laddres" runat="server" Text="Label"></asp:Label></p>
<p><asp:Label ID="Label20" runat="server" Text="您的爱好是:"></asp:Label><asp:Label ID="llove" runat="server" Text="Label"></asp:Label></p>
<p><asp:Label ID="Label22" runat="server" Text="您的备注:"></asp:Label><asp:Label ID="lremark" runat="server" Text="Label"></asp:Label></p>
<p><asp:Label ID="Label24" runat="server" Text="您的照片:"></asp:Label></p>
<p>
<asp:Image ID="Image1" runat="server" Height="136px" Width="130px" />
</p>
</div> </div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Data;
using DBHelper;
using MySql.Data.MySqlClient; public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string sql = "select * from s_province";
DataSet ds = SqlHelper.ExecuteDataSetText(sql, null);
this.addres.DataTextField = "ProvinceName";
this.addres.DataValueField = "ProvinceId";
this.addres.DataSource = ds.Tables[0];
this.addres.DataBind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (!IsPostBack)
{
string name = this.name.Text.Trim();
string passwd = this.passwd.Text.Trim();
string email = this.email.Text.Trim();
int sex = 0;
if (this.RadioButton1.Checked == true)
{
sex = 1;
}
else
{
sex = 0;
} string addres = this.addres.SelectedItem.Text;
string love = "";
for (int i = 0; i < CheckBoxList1.Items.Count; i++)
{
if (this.CheckBoxList1.Items[i].Selected == true)
{
love += this.CheckBoxList1.Items[i].Text.Trim() + ",";
} }
string remark = this.remark.Text.Trim(); string pos_name = "";
//文件上传
string upload = FileUpload1.PostedFile.FileName;
string images = "images/";
string pic_abs = Server.MapPath(images);
string pirefix = Path.GetExtension(upload);
string daname = "";
if (pirefix != ".jpg")
{
RequiredFieldValidator9.ErrorMessage = "上传文件格式不正确";
}
else
{
if (!Directory.Exists(pic_abs))
{
Directory.CreateDirectory(pic_abs);
}
//格式 daname = DateTime.Now.Ticks.ToString() + pirefix; //文件名防重复 pos_name = pic_abs + daname;
FileUpload1.SaveAs(pic_abs + daname); RequiredFieldValidator9.ErrorMessage = "上传文件成功";
}
//添加数据库
string sql = "insert into memberinfo(name,passwd,email,sex,love,remark,imgpath)values(@name,@passwd,@email,@sex,@love,@remark,@imgpath)";
MySqlParameter d1 = new MySqlParameter("@name", name);
MySqlParameter d2 = new MySqlParameter("@passwd", passwd);
MySqlParameter d3 = new MySqlParameter("@email", email);
MySqlParameter d4 = new MySqlParameter("@sex", sex);
MySqlParameter d5 = new MySqlParameter("@love", love.Trim(','));
MySqlParameter d6 = new MySqlParameter("@remark", remark);
MySqlParameter d7 = new MySqlParameter("@imgpath", pos_name);
MySqlParameter[] pa = new MySqlParameter[] { d1, d2, d3, d4, d5, d6, d7 };
int x = SqlHelper.ExecteNonQueryText(sql, pa);
if (x > 0)
{
Response.Write("<script>alert('创建成功')</script>"); } //div选择
this.lname.Text = name;
this.lpasswd.Text = passwd;
this.lemail.Text = email;
this.lsex.Text = "";
if (RadioButton1.Checked == true)
{
this.lsex.Text = "男";
}
else
{
this.lsex.Text = "女"; }
this.llove.Text = love.Trim(',');
this.lremark.Text = remark;
this.laddres.Text = addres;
this.Image1.ImageUrl = @"./images/" + daname; } }
protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
{ }
}
ASp.net 注册的更多相关文章
- (转)asp.net注册实现下一步
在asp.net中有两种容器控件,其中包括panel和placeholder控件. 使用panel控件可以对控件进行分组.一帮助组织web窗体也的内容,将控件组织在面板中,可提供有关在运行时控件应如何 ...
- 使用ASP.NET注册工具aspnet_regiis.exe注册IIS
该工具的名称为aspnet_regiis.exe,在32位机上,该工具存在于C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727,在64位机中“Framework ...
- winserver 08 64位安装sql05 64位提示asp版本注册
将打开 安装IIS 6.0的就可以了,然后重启下
- Asp.Net 注册 邮箱激活
数据库 表的设计 State为用户状态 0为禁用 1为可用 默认为0,下面有个UserGUID,这个字段将来用于激活账户 首先你要写一个表单,验证码神马的,这个我就不写了..直接写处理的 代码在 ...
- ASP.NET中使用Entity Framework开发登陆注册Demo
这里更多的是当作随身笔记使用,记录一下学到的知识,以便淡忘的时候能快速回顾 当前步骤是该项目的第一部分 第一部分(当前) 第二部分 大完结版本 直接上步骤,有类似的开发登陆注册也可以参考. 登陆注册的 ...
- ASP.NET MVC 从零开始 - 请求处理
这篇文章是从我的 github 博客 lxconan.github.io 导入的. 这是这个系列的第三篇了.前两篇文章请参见: ASP.NET MVC 从零开始 - Create and Run AS ...
- IIS7如何部署asp.net网站
第一步:发布网站 右键asp.net web项目,选择发布, 然后新建配置文件名称并选择 "文件系统" 发布方法. 目标位置选择本地新建的文件夹如: IISWebSite 第二 ...
- ASP DropDownList部分选项无法触发回传问题
今天偶然碰到这个问题,一个通过后台绑定的DropDownList控件出现部分选项触发事件,部分选项不触发事件的问题: 原因是多个OPTION的Value值一致,导致ASP事件注册失败,只要在绑定过程中 ...
- asp.net 网站 或者web Api 发布
asp.net 发布iis时可能遇到的内部服务错误常见的有两种: 1.如下图,500.19 Internal Server Error(内部服务错误) 这种错误可能是由于本机的注册表中的asp.net ...
随机推荐
- 使用UDEV绑定ASM多路径磁盘
OS版本:RHEL6.4 1) 找出目标磁盘的分区别名 # dmsetup ls |grep data data01 (253:9) data04 (253:4) data03 (253:3) dat ...
- Java FX中TreeView节点选中和双击事件监听
TreeItem<String> treeRoot = new TreeItem<String>("Root"); treeRoot.setExpanded ...
- .NET: WPF 路由事件
(一)使用WPF内置路由事件 xaml: <Window x:Class="WpfApplication1.MainWindow" xmlns="http://sc ...
- jquery中的json操作
$(function() { var json = [ { "id" : "1", "tagName" : "apple" ...
- zw版【转发·台湾nvp系列Delphi例程】CheckDifference1
zw版[转发·台湾nvp系列Delphi例程]CheckDifference1 procedure TForm1.Button1Click(Sender: TObject);var img, img1 ...
- 读 《JavaScript: The Good Parts》 有感
提炼出一门语言或技术的 Good Parts, 使用该子集去构造健壮稳固的应用. 我们总是倾向于去学习和使用所有的语言特性,好像凡是新的,凡是提供了的, 就有必要去使用: 这本书告诉我们, 要有选择性 ...
- 搬瓦工的ShadowSock设置方法:
- LUA笔记之字符串
LUA提供了自动数值转换, 基本上说是乱来也不为过, 就当做是不熟悉数据结构吧, 例子: print("10" + 1) --> 11 print("10 + 1& ...
- 各种数据库连接代码(java)
SqlServer2000 Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); URL = "j ...
- JSP注意点
一.JSP页面会编译成一个Servlet类,每个Servlet在容器中只有一个实例:在JSP中声明的变量是成员变量,成员变量只在创建实例时初始化,该变量的值将一直保存,直到实例销毁: 二.输出表达式& ...