国家指南 ASP.NET项目开发指南:个人信息的修改(2)[1]
ASP.NET项目开发指南:个人信息的修改(2)[1]
个人信息的修改( )
ST_UserAdd aspx cs的主要代码及其解释
在此主要是读取用户信息 显示到每个Web控件 主要代码如程序 所示
程序 ST_UserAdd aspx cs
protected void Page_Load(object sender System EventArgs e)
{
Response Cache SetCacheability(HttpCacheability NoCache)
//判断是否是第一次加载
if(!IsPostBack)
{
//初始化用户信息
ST_BookBiz ST_User st_user = new STGROUP ST_BookBiz ST_User()
//编辑操作
if(Request[ Action ]== edit )
{
ST_BookBiz ST_Identity identity = new
ST_BookBiz ST_Identity(User Identity Name)
int userid = identity UserID;
if (userid == )
Response Redirect( /ST_Login aspx )
st_entity = st_user GetUserInfo(userid)
txtNumber Text = userid ToString()
txtName Text = st_entity ST_Name;
txtAddress Text = st_entity ST_Address;
txtEmail Text = st_entity ST_Email;
txtPhone Text = st_entity ST_Telephone;
txtPostCode Text = st_entity ST_Postcode;
txtTrueName Text = st_entity ST_TrueName;
txtPass Text = st_entity ST_Pass;
RadioButtonList SelectedIndex =
RadioButtonList Items IndexOf(RadioButtonList Items
FindByText(st_entity ST_Gender))
txtName ReadOnly = true;
}
}
}
【代码说明】代码第 ~ 行根据用户ID读取用户信息 代码第 ~ 行显示这些信息 在此要提醒读者的是代码第 ~ 行 注意读取值如何与RadioButtonList控件进行绑定
说明 Items IndexOf()方法用来获取所选择项的索引
触发btnOK_Click事件后 即可进行个人信息的添加或修改操作 主要代码如程序 所示
程序 ST_UserAdd aspx cs
protected void btnOK_Click(object sender System EventArgs e)
{
![国家指南 ASP.NET项目开发指南:个人信息的修改(2)[1]](http://img.zhputi.com/uploads/e0b8/e0b86a55fd25ee1771400da94380338c35029.jpg)
ST_BookBiz ST_User st_user = new STGROUP ST_BookBiz ST_User()
//判断条件 名称不允许为空
if(txtName Text== )
Response Write( <script defer>alert( 名称不允许为空! )
</script> )
else if(txtPass Text== )
Response Write( <script defer>alert( 密码不允许为空! )
</script> )
else if(txtPass Text != txtPass Text)
{
Response Write( <script defer>alert( 密码不一致! )
</script> )
}
else if (st_user ST_IsUserExist(txtName Text Trim()) &&
Request[ Action ] == add )
{
Response Write( <script defer>alert( 用户名已经存在! )
</script> )
}
else
{
ST_BookBiz ST_Identity identity = new
ST_BookBiz ST_Identity(User Identity Name)
int userid = identity UserID;
//用户信息的添加或删除操作
if (Request[ Action ] == add )
{
userid = ;
st_entity ST_Name = txtName Text;
st_entity ST_Address = txtAddress Text;
st_entity ST_Email = txtEmail Text;
st_entity ST_Telephone = txtPhone Text;
st_entity ST_Postcode = txtPostCode Text ;
st_entity ST_TrueName = txtTrueName Text;
st_entity ST_Pass = txtPass Text;
st_entity ST_Gender = RadioButtonList SelectedValue;
userid = st_user InsertUser(st_entity)
identity = new ST_BookBiz ST_
Identity(txtName Text Trim()
userid)
Context User = new ST_BookBiz
ST_Principal(identity new
string[] { User })
identity Name = txtName Text;
identity Roles = User ;
identity Save()
//身份验证票
FormsAuthentication SetAuthCookie(txtName Text false)
Response Redirect( /ST_Common/ST_Main aspx )
}
else if (Request[ Action ] == edit && userid!= )
{
//修改信息
st_entity ST_Name = txtName Text;
st_entity ST_Address = txtAddress Text;
st_entity ST_Email = txtEmail Text;
st_entity ST_Telephone = txtPhone Text;
st_entity ST_Postcode = txtPostCode Text;
st_entity ST_TrueName = txtTrueName Text;
st_entity ST_Pass = txtPass Text;
st_entity ST_Gender = RadioButtonList SelectedValue;
st_entity ST_UserID = userid;
st_user UpdateUser(st_entity)
string str = <script language=
javascript>alert( 更新成功! )
</script> ;
Response Write(str)
}
}
}
【代码说明】代码第 ~ 行首先判断用户的用户名和密码输入是否正确 代码第 ~ 行实现用户信息的添加 代码第 ~ 实现用户信息的修改
lishixinzhi/Article/program/net/201311/15818