zoukankan
html css js c++ java
NHibernate 做个小项目来试一下吧 六
BLL层也完成了,现在来做 界面吧,在添加一个新建ASP.Net Web应用程序的新建工程
现搞个 注册的页吧,
(图片上传上就成这个样子了
)
using
System;
using
System.Collections;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Web;
using
System.Web.SessionState;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.HtmlControls;
using
guestbook.BLL;
using
guestbook.Dal;
using
guestbook.data;
namespace
guestbook.web
{
/**/
///
<summary>
///
Register 的摘要说明。
///
</summary>
public
class
Register : System.Web.UI.Page
{
protected
System.Web.UI.WebControls.TextBox txtUserName;
protected
System.Web.UI.WebControls.TextBox txtEmail;
protected
System.Web.UI.WebControls.Button Button1;
protected
System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator1;
protected
System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
protected
System.Web.UI.WebControls.RequiredFieldValidator valUN;
protected
System.Web.UI.WebControls.TextBox txtPwd;
private
void
Page_Load(
object
sender, System.EventArgs e)
{
//
在此处放置用户代码以初始化页面
}
Web 窗体设计器生成的代码
#region
Web 窗体设计器生成的代码
override
protected
void
OnInit(EventArgs e)
{
//
//
CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base
.OnInit(e);
}
/**/
///
<summary>
///
设计器支持所需的方法 - 不要使用代码编辑器修改
///
此方法的内容。
///
</summary>
private
void
InitializeComponent()
{
this
.Button1.Click
+=
new
System.EventHandler(
this
.Button1_Click);
this
.Load
+=
new
System.EventHandler(
this
.Page_Load);
}
#endregion
private
void
Button1_Click(
object
sender, System.EventArgs e)
{
if
(Page.IsValid)
{
string
username
=
txtUserName.Text;
string
Email
=
txtEmail.Text;
string
pwd
=
txtPwd.Text;
users newUser
=
new
users();
newUser.Name
=
username;
newUser.email
=
Email;
newUser.password
=
pwd;
if
(
!
CreateAccount(newUser))
{
valUN.ErrorMessage
=
"
用户名已被注册,请另选!
"
;
valUN.IsValid
=
false
;
}
}
}
private
bool
CreateAccount(users user)
{
try
{
usersbll bll
=
new
usersbll();
bll.UserAdd(user);
HttpContext.Current.Session[
"
AccountInfo
"
]
=
user;
HttpContext.Current.Response.Redirect(
"
Default.aspx
"
,
true
);
}
catch
{
return
false
;
}
return
true
;
}
}
}
这个过程 总体来说比较顺利,但是在最后测试的时候 碰到了一点点问题 ,就是一开始,怎么也插入不了数据,后来才想起来,没有把NHibernate的配置复制到 web.config中去,晕啊,太粗心了我
还有一个要注意的就是,
<
configSections
>
<
section
name
="nhibernate"
type
= "System.Configuration.NameValueSectionHandler,System,Version=1.0.3300.0,Culture=neutral, PublicKeyToken=b77a5c561934e089"
/>
</
configSections
>
上面这一节 一定要 放在 <configSection>标签下在, 放到其它位置 就会报错。OK继续
本
作品
由
平波
创作,采用
知识共享署名 2.5 中国大陆许可协议
进行许可。
查看全文
相关阅读:
css-断网图片加载失败,图片表情与文字对齐
工作中遇到一些不会写的样式
基础知识题目
前端基础知识html css
js match
jquery.extend()与jquery.fn.extend()的区别
js apply 与 call
jdk安装
js数组操作各种方法
js获取日期
原文地址:https://www.cnblogs.com/9527/p/53047.html
最新文章
事件处理程序的性能与优化
flex布局2
flex布局1
数组和对象的遍历
跨浏览器的事件对象
跨浏览器的事件处理程序
在Gulp中使用BrowserSync
mac 终端调起 chrome浏览器
This package has been marked as private
如何发布Node模块到NPM社区
热门文章
rn app 发布注意事项
node安装
Dockerfile文件内容
docker 安装
Xcode8上传app一直显示正在处理
常用命令行
html 网页调起QQ弹窗
vue中使用 async & await
git
js encodeURI 和 encodeURIComponent 的区别
Copyright © 2011-2022 走看看