ASP.NET项目开发指南:个人信息的修改(1)

ASP.NET项目开发指南:个人信息的修改(1),第1张

  个人信息的修改( )

在用户界面中单击右上角的 我的账户 超链接时 将进入ST_UserAdd aspx页面 如图 所示

图   修改个棚粗人信息

ST_UserAdd aspx的主要HTML代码

ST_UserAdd aspx的主要HTML代码如程序 所示

程序   ST_UserAdd aspx

  <form id= Form runat= server >

      <TABLE id= Table cellSpacing= cellPadding= border=

          align=center>

          <TR>

              <TD colSpan= >TD>

          TR>

          <TR>

              <TD>用户编号 TD>

              <TD style= width: px ><asp:textbox id= txtNumber

      runat= server ReadOnly= True >系统自动生成asp:textbox>TD>

              <TD>用户名称 TD>

              <TD>

              <asp:textbox id= txtName runat= server

                  MaxLength= >asp:textbox>最多 个字符

              TD>

          TR>

          <TR>

              <TD>真实姓名 TD>

              <TD style= width: px ><asp:textbox id= txtTrueName

                  runat= server >asp:textbox>

              TD>

              <td>详细地址 td>

              <td>

                  <asp:textbox id= txtAddress

                      runat= server >asp:textbox>td>

          TR>

          <TR>

              <TD>联系电话 TD>

              <TD style= width: px ><asp:textbox id= txtPhone

                  runat= server >asp:textbox>

              TD>

              <td>Email:td>

              <td>

                  <asp:textbox id= txtEmail

                      runat= server >asp:textbox>td>

          TR>

          <TR>

              <TD>邮编 TD>

              <TD style= width: px ><asp:textbox id= txtPostCode

                  runat= server >asp:textbox>

              TD>

              <td>性别 td>

              <td>

                  <asp:RadioButtonList ID= RadioButtonList

                      runat= server RepeatDirection= Horizontal >

链颂镇                       <asp:ListItem Value= 男 >男asp:ListItem>

                      <asp:ListItem Value= 女 >女asp:ListItem>

           樱毁       asp:RadioButtonList>td>

          TR>

          <TR>

              <TD>用户密码 TD>

              <TD style= width: px ><asp:textbox id= txtPass

                  runat= server TextMode= Password >asp:textbox>

              TD>

              <td>确认密码 td>

              <td>

                  <asp:textbox id= txtPass runat= server

              TextMode= Password >asp:textbox>td>

          TR>

          <tr>

              <td colspan= >

                  <asp:Button id= btnOK CssClass= button

  runat= server Text= 确定 onclick= btnOK_Click >asp:Button>td>

          tr>

      TABLE>

  form>

【代码说明】代码第 ~ 行是一个RadioButtonList控件 这里显示了两个单选按钮 每个ListItem是一个选项 其Value属性就是用户看到的选项内容 其他控件很简单 这里不再赘述

       返回目录 ASP NET项目开发指南

       编辑推荐

       ASP NET MVC 框架揭秘

       ASP NET开发宝典

lishixinzhi/Article/program/net/201311/15819

  个人信息的修改( )

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)

  {

       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


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/12281531.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-22
下一篇2023-05-22

发表评论

登录后才能评论

评论列表(0条)

    保存