Learning PetShop3.0 (2) User Registration (CreateAccount. aspx)

Source: Internet
Author: User

Learning PetShop3.0 (2) User Registration (CreateAccount. aspx)

Click Register in SignIn. aspx
Now, go to CreateAccount. aspx.

1) Fill in My Account. There is nothing worth introducing, that is, add three textBox and three equiredFieldValidator. Very simple. The input is complete. The backend calls WebComponents. CleanString. InputText (string inputString, int
MaxLength. It is estimated that the program is simple, or Microsoft believes that CustomerValidator does not belong to the things to be described in this example. The rules for inputting strings are not tested by controls, that is, the input of emails can be a character, as long as it is not null.

2) Fill in My Address. In this example, a UserControl is implemented. Because there are multiple needs, such as Account Modification and order address. In this example, a Model class is also created for the Address, and the return value of an attribute of the AddressUI control mentioned above is instantiated. This property has the get and set methods. When an Account is modified, the user information returned from the database can be directly assigned a value using an AddressInfo object. This is a bit like JSF. It binds a able control to a bean in the background.

3) Fill in My Preferences. Like filling in My Address, a UserControl is implemented. Slightly different, the model class is not created for Preferences, and only four attributes are written to access Language, Category, IsShowFavorites, and IsShowBanners. Then, the AddressInfo object and the above four attributes are used to instantiate AccountInfo.

4) write data to the database and use CreateAccount (AccountInfo
NewAccountInfo ). If the verification succeeds, the new user information is written into the Session and set to pass verification. The default. aspx page is displayed.

 

Public bool CreateAccount (AccountInfo newAccountInfo ){
Try {
Account account = new Account ();
Account. Insert (newAccountInfo );
HttpContext. Current. Session [ACCOUNT_KEY] = newAccountInfo;
FormsAuthentication. SetAuthCookie (newAccountInfo. UserId, false );
HttpContext. Current. Response. Redirect (URL_ACCOUNTCREATE, true );
} Catch {
Return false;
}
Return true;
}


5) The BLL. account. Insert (newAccountInfo) function is the same as the SignIn function. Instantiate Accout using a DALFactory and reflection. The rest is just simple database access.

Public void Insert (AccountInfo account ){
If (account. UserId. Trim () = string. Empty)
Return;
IAccount dal = PetShop. DALFactory. Account. Create ();
Dal. Insert (account );
}


6) There is no excessive judgment on the repetition of Accout IDs. Only the primary key is used for the judgment. If BLL. account. Insert (newAccountInfo) is repeated, false is returned. The interface outputs "Duplicate user ID! Please try again ", Microsoft seems to think that the cause of Account creation error is only repeated users.

7) log on to the MyAccount. aspx page. MyAccount. aspx has a blockquote Html tag, which is scaled to the right. The problem is not great. The only OnLoad event in the background code that requires attention is that different success information is displayed based on the query string after the action, including creating accounts, updating accounts, and logging on to accounts.

Case "create ":
LblMessage. Text = "Your account was successfully created .";
Break;
Case "update ":
LblMessage. Text = "Your account was successfully updated .";
Break;
Case "signIn ":
LblMessage. Text = "Welcome to the. NET Pet Shop Demo .";
Break;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.