熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

ASP.NET項目開發指南:個人信息的修改(2)[1]

2022-06-13   來源: .NET編程 

    個人信息的修改(

  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)

              }

        }

    }

  【代碼說明】代碼第~行首先判斷用戶的用戶名和密碼輸入是否正確代碼第~行實現用戶信息的添加代碼第~實現用戶信息的修改

[]  []  


From:http://tw.wingwit.com/Article/program/net/201311/15818.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.