Presentation is loading. Please wait.

Presentation is loading. Please wait.

Working with ASP.NET Controls What is ASP.NET Using server controls in your pages Allowing users to create their own accounts Creating a login page Letting.

Similar presentations


Presentation on theme: "Working with ASP.NET Controls What is ASP.NET Using server controls in your pages Allowing users to create their own accounts Creating a login page Letting."— Presentation transcript:

1 Working with ASP.NET Controls What is ASP.NET Using server controls in your pages Allowing users to create their own accounts Creating a login page Letting users change their passwords

2 What is ASP.NET? ASP.NET is essentially a set of controls for a building dynamic, data-driven Web site. Suppose you go to www.google.com, type in something. A moment later, Google sends back a page with links to a bunch of Web sites. Where did that page come from? How does that work? Google’s Web server had to take an active role in creating the page it sent to your Web browser. The pages that Google sends out from its Web server are dynamic in that each page contains only links that match the words the user searched for. Those results are datadriven in that all those links are stored in a database at Google’s site. Making your Web server take an active role in creating the pages it sends is what ASP.NET is all about

3 What is ASP.NET?- Continue You can’t send pages that contain server controls directly to clients. Clients can’t execute server controls. The server uses data from the database and information in the.aspx page to determine exactly what HTML is needed on the client PC. Then the server creates the appropriate page and sends it to the client.

4 What is ASP.NET?- Continue In Visual Web Developer, the Toolbox shows the names of commonly used.NET Server controls, categorized into groups like Data, Validation, Navigation, Login, and so forth. These tools are visible only when you’re editing a Web form (.aspx page). The server controls are hidden when you’re editing an.HTML page.

5 Adding a Server Control to a Page

6 Tweaking server controls in Design view In Design view, clicking an ASP.NET control selects the control. The Properties sheet shows the name and properties of the control. Play with the Auto- Format

7 Tweaking server controls in Source view Controls in the.NET Framework are organized into a hierarchical namespace, a place to keep them that works much the same way as the hierarchical organization of the folders on your hard disk that keep your files. In the Properties window, System.Web.UI.WebControls.Login is the full name of the Login control within the.NET Framework namespace. Go to TestMaster.cs

8 Tweaking server controls in Source view

9 Using the Common Tasks menu Using Auto Format Clicking that button takes you to an Auto Format dialog box, where you see a list of scheme names and a preview window. Choose Auto Format ➪ Classic scheme, and click OK. Converting a control to a template The Control is made of several smaller controls. How can I change one individual control? When you choose Convert to Template, a complex visual control like Login is divided into its individual components. Then, the “Convert to Template” option on the Common Tasks menu is replaced with a Reset option. Administering the Web site The Administer Website option on the Common Tasks menu is just a shortcut to the Web Site Administration Tool already discussed. No need to switch to that tool Editing templates (we will talk later)

10 ASP.NET Login Controls Pointer: Not really a Login control. Login: Presents a control that allows users to log into their accounts with their user name and password. LoginView: Lets you show different stuff to different users based on whether they’re anonymous or logged in. PasswordRecovery: As the name implies, presents fields that allow a user to recover a forgotten password. LoginStatus: Displays a Login link to anonymous users, or a Logout link to authenticated users. LoginName: Displays nothing to an anonymous user; displays an authenticated user’s login name. CreateUserWizard: Provides a fill-in-the-blanks form for creating a new user account. Use it in your Web sites to allow people to create their own accounts. ChangePassword: Provides a form that allows a user to change his or her password.

11 Allowing Users to Create an Account If your site will allow anyone to create an account, you need a page that allows users to enter the appropriate data. To do this use the CreateUserWizard control because it displays on a Web page all the fields needed for a user to create an account. To create a new page for the control, right-click the site folder or subfolder in Solution Explorer and choose Add New Item (CreateAcct.aspx). Drag a CreateUserWizard tool from the Login category of the Toolbox onto the page

12 Assigning new users to a role The CreateUserWizard control doesn’t automatically assign a new user to a role. If you want to put all the people who sign up through the CreateUserWizard control into a specific role, add a little code: In design view, select the CreateUserWizard control. Its name appears in the Properties sheet when selected. In the Properties sheet, click the Events (lightning bolt) button. Double-click the CreatedUser event. You’re taken to the code-behind page for the page you’re designing; The cursor is already in the event procedure, right where you type its code. Type the following at the cursor position, substituting your own data for the italics, as follows: Roles.AddUserToRole(ctrlName.UserName,”roleName”);

13 Few CreateUserWizard tips A couple of noteworthy properties include ContinueDestinationPageURL and LoginCreatedUser. You can set the ContinueDestinationPageURL property to whatever page you want to have open when the user clicks Continue after successfully creating an account. The LoginCreatedUser property determines whether or not the user is logged in automatically after creating the account. The default is True, the user is logged in.

14 Testing the control Run the page and test the creation of a new account. Remember At least 7-chars long passwords At least 1 non-alphanumeric char To verify that the process worked, you can choose Website ➪ ASP.NET Configuration from the menu bar to open the Web Site Administration Tool. Click the Security tab, and then Click Manage Users. The new user should be listed.

15 Providing a Login Link To make your site easy to use, you need a login link on every page. An easy way to provide this is to put a link to the Login.aspx page into the Master Page for your site. But a regular link that always showed Login would be confusing for people who have already logged in. The link should show Logout or something else for people who are already logged in. That’s where the LoginStatus control comes in. You must create a page named Login.aspx in your site’s root folder before you can actually use the controls described in this EXAMPLE. Otherwise, when you try to test the control in a Web browser, you’ll get an error message indicating that the Login.aspx page cannot be found.

16 The LoginStatus contr Drag a LoginStatus control to a Master Page Close and save the Master Page Then, right-click any page that uses the Master Page and choose View in Browser. In the browser, clicking the Login link should take you to Login.aspx. If your Default.aspx page uses the Master Page, you’ll see that the link has changed from Login to Logout, because you’re logged in.

17 The LoginName control This control shows nothing to anonymous users. For authenticated users, the control displays the user’s login name. Typically you use the LoginName control with the LoginView control.

18 The LoginView control The LoginView control can tell the difference between anonymous and authenticated users. But it’s not limited to showing text or a picture. You can use it to show just about anything, even ASP.NET server controls. To use the control, just drag it to the Web page or Master page. The control is shaped as a box. The box has two different views, but you only see one view at a time. Choose one of: Anonymous Template: Content that anonymous users see. LoggedIn Template: Content that only authenticated users see.


Download ppt "Working with ASP.NET Controls What is ASP.NET Using server controls in your pages Allowing users to create their own accounts Creating a login page Letting."

Similar presentations


Ads by Google