个人信息的修改()
ST_UserAddaspxcs的主要代码及其解释
在此主要是读取用户信息显示到每个Web控件主要代码如程序所示
程序 ST_UserAddaspxcs
protected void Page_Load(object sender SystemEventArgs e)
{
ResponseCacheSetCacheability(HttpCacheabilityNoCache)
//判断是否是第一次加载
if(!IsPostBack)
{
//初始化用户信息
ST_BookBizST_User st_user = new STGROUPST_BookBizST_User()
//编辑操作
if(Request[Action]==edit)
{
ST_BookBizST_Identity identity = new
ST_BookBizST_Identity(UserIdentityName)
int userid = identityUserID;
if (userid == )
ResponseRedirect(/ST_Loginaspx)
st_entity = st_userGetUserInfo(userid)
txtNumberText = useridToString()
txtNameText = st_entityST_Name;
txtAddressText = st_entityST_Address;
txtEmailText = st_entityST_Email;
txtPhoneText = st_entityST_Telephone;
txtPostCodeText = st_entityST_Postcode;
txtTrueNameText = st_entityST_TrueName;
txtPassText = st_entityST_Pass;
RadioButtonListSelectedIndex =
RadioButtonListItemsIndexOf(RadioButtonListItems
FindByText(st_entityST_Gender))
txtNameReadOnly = true;
}
}
}
【代码说明】代码第~行根据用户ID读取用户信息代码第~行显示这些信息在此要提醒读者的是代码第~行注意读取值如何与RadioButtonList控件进行绑定
说明ItemsIndexOf()方法用来获取所选择项的索引
触发btnOK_Click事件后即可进行个人信息的添加或修改操作主要代码如程序所示
程序 ST_UserAddaspxcs
protected void btnOK_Click(object sender SystemEventArgs e)
{
ST_BookBizST_User st_user = new STGROUPST_BookBizST_User()
//判断条件名称不允许为空
if(txtNameText==)
ResponseWrite(<script defer>alert(名称不允许为空!)
</script>)
else if(txtPassText==)
ResponseWrite(<script defer>alert(密码不允许为空!)
</script>)
else if(txtPassText != txtPassText)
{
ResponseWrite(<script defer>alert(密码不一致!)
</script>)
}
else if (st_userST_IsUserExist(txtNameTextTrim()) &&
Request[Action] == add)
{
ResponseWrite(<script defer>alert(用户名已经存在!)
</script>)
}
else
{
ST_BookBizST_Identity identity = new
ST_BookBizST_Identity(UserIdentityName)
int userid = identityUserID;
//用户信息的添加或删除操作
if (Request[Action] == add)
{
userid = ;
st_entityST_Name = txtNameText;
st_entityST_Address = txtAddressText;
st_entityST_Email = txtEmailText;
st_entityST_Telephone = txtPhoneText;
st_entityST_Postcode = txtPostCodeText ;
st_entityST_TrueName = txtTrueNameText;
st_entityST_Pass = txtPassText;
st_entityST_Gender = RadioButtonListSelectedValue;
userid = st_userInsertUser(st_entity)
identity = new ST_BookBizST_
Identity(txtNameTextTrim()
userid)
ContextUser = new ST_BookBiz
ST_Principal(identity new
string[] { User })
identityName = txtNameText;
identityRoles = User;
identitySave()
//身份验证票
FormsAuthenticationSetAuthCookie(txtNameText false)
ResponseRedirect(/ST_Common/ST_Mainaspx)
}
else if (Request[Action] == edit && userid!=)
{
//修改信息
st_entityST_Name = txtNameText;
st_entityST_Address = txtAddressText;
st_entityST_Email = txtEmailText;
st_entityST_Telephone = txtPhoneText;
st_entityST_Postcode = txtPostCodeText;
st_entityST_TrueName = txtTrueNameText;
st_entityST_Pass = txtPassText;
st_entityST_Gender = RadioButtonListSelectedValue;
st_entityST_UserID = userid;
st_userUpdateUser(st_entity)
string str = <script language=
javascript>alert(更新成功!)
</script>;
ResponseWrite(str)
}
}
}
【代码说明】代码第~行首先判断用户的用户名和密码输入是否正确代码第~行实现用户信息的添加代码第~实现用户信息的修改
[] []