ASP.NET简单登录注册实例
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td> <asp:Label ID="Label1" runat="server" Text="用户名:"></asp:Label> </td>
<td> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td> <asp:Label ID="Label2" runat="server" Text="密码:"></asp:Label> </td>
<td> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td><asp:Button ID="Button2" runat="server" Text="登录" onclick="Button2_Click" /> </asp:Label> </td>
<td> <asp:Button ID="Button1" runat="server" Text="注册" onclick="Button1_Click" /> </asp:TextBox></td>
</tr>
</table>
</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.Data.SqlClient;
using System.Data; namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
//登录
protected void Button2_Click(object sender, EventArgs e)
{
string name = TextBox1.Text;
string pwd = TextBox2.Text;
if (name!=null||pwd!=null)
{
string sql = "select count(0) from student where stuName=@a and stuNo=@b";//获取数据中的信息
SqlParameter p1 = new SqlParameter("@a",name);
SqlParameter p2 = new SqlParameter("@b",pwd);
//连接数据库
string connStr = "server=DESKTOP-QQGOIKH;uid=sa;pwd=123;database=stuDB";
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
SqlCommand cmd = new SqlCommand(sql,conn);
cmd.Parameters.Add(p1);
cmd.Parameters.Add(p2);
object obj = cmd.ExecuteScalar();
conn.Close();
int i = (int)obj;
if (i>)
{
Response.Redirect("WebForm2.aspx");
}
else
{
Response.Write("登录失败");
}
}
else
{
return;
} }
//注册
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("WebForm3.aspx"); }
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm3.aspx.cs" Inherits="WebApplication1.WebForm3" %> <!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td><asp:Label ID="Label1" runat="server" Text="用户名:"></asp:Label> </td>
<td> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td><asp:Label ID="Label2" runat="server" Text="密码:"></asp:Label> </td>
<td><asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> </td>
</tr>
<tr>
<td> <asp:Button ID="Button1" runat="server" Text="注册" onclick="Button1_Click" /> </td>
<td> <asp:Button ID="Button2" runat="server" Text="返回" onclick="Button2_Click" /> </td>
</tr>
</table>
</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.Data;
using System.Data.SqlClient; namespace WebApplication1
{
public partial class WebForm3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
//注册
protected void Button1_Click(object sender, EventArgs e)
{
string name = TextBox1.Text;
string pwd = TextBox2.Text;
if (name!=null||pwd!=null)
{
string sql = "insert into enter values(@a,@b)";
SqlParameter[] sp = new SqlParameter[];
sp[] = new SqlParameter("@a",TextBox1.Text);
sp[] = new SqlParameter("@b",TextBox2.Text);
SqlConnection conn = new SqlConnection("server=STER-PC;uid=sa;pwd=123;database=t2");
conn.Open();
SqlCommand comm = new SqlCommand(sql,conn);
comm.Parameters.AddRange(sp);//添加数组
int i = comm.ExecuteNonQuery();
conn.Close();
if (i>)
{
Response.Write("注册成功");
}
else
{
Response.Write("注册失败");
}
}
else
{
Response.Write("请填写内容");
}
}
//返回
protected void Button2_Click(object sender, EventArgs e)
{
Response.Redirect("WebForm1.aspx");
}
}
}
ASP.NET简单登录注册实例的更多相关文章
- tornado 08 数据库-ORM-SQLAlchemy-表关系和简单登录注册
tornado 08 数据库-ORM-SQLAlchemy-表关系和简单登录注册 引言 #在数据库,所谓表关系,只是人为认为的添加上去的表与表之间的关系,只是逻辑上认为的关系,实际上数据库里面的表之间 ...
- Node.js_express_中间件 middleware_登录/注册实例源代码
静态资源: 都写死了的资源,如 css,html 解析规则: 所有路由和中间件都在一个数组中,js 引擎会按照代码先后顺序添加路由和中间件 当请求发送到服务器时,服务器获取当前的请求信息(请求方式.请 ...
- 简单登录注册实现(Java面向对象复习)
简单登录注册的实现(面向对象的复习) 需求: 设计用户类,包含用户名和密码两个属性 设计LoginDemo类设计用户登录方法 用户有三次登录机会,如果连续三次登录失败则退出程序 功能实现页面: ...
- Vue学习之路之登录注册实例代码
Vue学习之路之登录注册实例代码:https://www.jb51.net/article/118003.htm vue项目中路由验证和相应拦截的使用:https://blog.csdn.net/wa ...
- vue-cli——vue-resource登录注册实例
前言 使用vue-resource请求接口非常方便,在使用前需安装vue-resource依赖并在入口文件main.js中声明. 实例功能简述 本实例只有简单的两个模块:登录和注册,主要演示如何用vu ...
- Struts2开发环境搭建,及一个简单登录功能实例
首先是搭建Struts2环境. 第一步 下载Struts2去Struts官网 http://struts.apache.org/ 下载Struts2组件.截至目前,struts2最新版本为2.3.1. ...
- MVC+三层+ASP.NET简单登录验证
通过制作一个登录小案例来搭建MVC简单三层 在View --Shared下创建一个母版页: <!DOCTYPE html> <html> <head> <me ...
- tornado框架基础08-sqlalchemy表关系和简单登录注册
01 一对一表关系 Module 需要先创建对应的 Module ,这里采用之前建立好的 User 和 UserDetails relationship from sqlalchemy.orm imp ...
- flask简单登录注册
效果图 发布问答页面需要登录才能访问,没有登录会跳转到登录页面 模板继承,正则验证,数据库迁移,md5加密 mysql 5.7 登录页面 登录后的发布问答页面,右上角会显示用户名和注销 项目代码:码云
随机推荐
- 夺命雷公狗—angularjs—3—表单验证的高级用法
其实我们的angularjs都是是块状代码,其实是可以在实际开发中保存下来以后就可以达到重复利用的目的了.. 废话不多说,直接上代码: <!doctype html> <html l ...
- 夺命雷公狗TP下关联查询
记录下我们常用的关联查询: public function add4(){ $id=$_GET['id']; $this->list = M("student")->t ...
- Trace Sys
ARM片上调试和跟踪解决方案(包括CoreSight体系结构,嵌入式跟踪宏单元(ETM),程序流程跟踪(PTM),ARM调试接口(ADI), 跟踪缓冲器(ETB),嵌入式交叉触发器(CTM)) Cor ...
- c语言 typedef
在C和C++编程语言中,typedef是一个关键字.它用来对一个资料类型取一个新名字.目的是为了使源代码更易于阅读和理解. 来看以下程式码: int coxes; int jaffa; ... c ...
- js对象遍历
js对象遍历可以使用比较普遍的方法:如下 var ss={aa:"aa",bb:"bb"}; for(var s in ss){ console.info(&q ...
- 转:VS2008 vs2010中JQUERY智能提醒
第一步: 安装VS 2008 SP1 VS 2008 SP1 在Visual Studio中加了更丰富的JavaScript intellisense支持,对很大部分的JavaScript库加了代码完 ...
- opencv之深拷贝及浅拷贝,IplImage装换为Mat
一.(1) 浅拷贝: Mat B; B = image // 第一种方式 Mat C(image); // 第二种方式 这两种方式称为浅copy,是由于它们有不同的矩阵头,但是它们共享内存空间,即 ...
- MapReduce之Writable相关类
当要在进程间传递对象或持久化对象的时候,就需要序列化对象成字节流,反之当要将接收到或从磁盘读取的字节流转换为对象,就要进行反序列化.Writable是Hadoop的序列化格式,Hadoop定义了这样一 ...
- 使用Json.Net处理json序列化和反序列化接口或继承类
以前一直没有怎么关注过Newtonsoft的Json.Net这个第三方的.NET Json框架,主要是我以前在开发项目的时候大多数使用的都是.NET自带的Json序列化类JavaScriptSeria ...
- Awk使用一例:获取ASCII可见字符
要做一个需求, 支持可见特殊字符的密码设置. 首先, 需要获取到所有可见特殊字符. 到网上搜索到 ASCII 字符表格, 并复制到文本文件 vschars.txt: 00 00 0 nul 100 4 ...