Archive for April, 2007

Assigning new users to a role The CreateUserWizard

Thursday, April 26th, 2007

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 CreateUser Wizard control into a specific role, add a little code. I know I haven t talked about code in this book, and now is not the time to get into details of writing code. However, for this example, I can just show you what to type. This technique only works if you ve already enabled Roles in the Web Site Administration Tool as discussed in Chapter 3. Also, you ll have to remember exactly how you spelled your role name, as it won t appear in any IntelliSense menu. If you want your CreateUserWizard control to automatically assign every new user to a specific role in your site, follow these steps: 1. In design view, select the CreateUserWizard control. Its name appears in the Properties sheet when selected. 2. In the Properties sheet, click the Events (lightning bolt) button. 3. 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. 4. Type the following at the cursor position, substituting your own data for the italics, as follows: Roles.AddUserToRole(ctrlName.UserName, roleName ); ctrlName refers to the name of your CreateUserWizard control. That would likely be CreateUserWizard1 if you let VWD name the control. When you type a roleName, make sure you spell it exactly as you did when creating the role in the Web Site Administration Tool. The code given here shows what my example looked like after adding a line of code to add the new user to my SiteMembers role. protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e) { Roles.AddUserToRole(CreateUserWizard1.UserName, SiteMembers ); } Typing code isn t like typing in English. In code you have to get every dot, comma, parenthesis, quotation mark, and semicolon exactly right. Spelling and blank spaces count a lot too. The code won t work if you don t type the line exactly right. 5. Close and save the code-behind page. Chapter 7: Working with ASP.NET Controls 133
Note: In case you are looking for affordable webhost to host and run your servlet application check Vision ecommerce web hosting services

To create a new page for the control, (Domain and web hosting)

Wednesday, April 25th, 2007

To create a new page for the control, right-click the site folder or subfolder in Solution Explorer and choose Add New Item. Choose Web Form and fill in the blanks as you see fit. I named mine CreateAcct.aspx. The other options are entirely up to you. I chose Visual C# as the language, as I routinely have in the other examples in this book, and selected the Place Code In Separate File option. I also used the Master Page described in Chapter 4 in my example. Anyway, after you ve created (or opened) a page, just drag a CreateUserWizard tool from the Login category of the Toolbox onto the page (or drag it into the Content placeholder in a Master Page). If you like, use the Auto Format option on the Common Tasks menu to style the form. Figure 7-8 shows an example in which I ve added a CreateUserWizard control to the Content placeholder on a page. I also used Auto Format on the Common Tasks menu to set the scheme to Classic, making the control easier to see. If you want to keep life simple, just close and save the page. You don t really have to do anything else to the control, all the stuff it needs to validate the user s entries, store the user s data in the SQL Server database, and so forth, is already done. If you want to customize the control later, you can do so at any time. It has a Common Tasks menu, templates, and so forth. You can press Help (F1) for help while customizing the control. Figure 7-8: Create User Wizard control in Design view. 132 Part II: Building Your Web Site
Note: In case you are looking for affordable webhost to host and run your servlet application check Vision make web site services

Starting a web site - PasswordRecovery: As the name implies, presents fields

Wednesday, April 25th, 2007

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. You can use all of these controls anywhere in any .aspx page, any Master Page, as well as in the Content placeholder of a page that uses a master. The next few sections discuss these controls more fully. I ll start with the CreateUserWizard control. 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. The CreateUserWizard control is just the ticket to do this because it displays on a Web page all the fields needed for a user to create an account. Figure 7-7: Login server controls in the Toolbox. Chapter 7: Working with ASP.NET Controls 131
Note: In case you are looking for affordable webhost to host and run your servlet application check Vision servlet hosting services

You can treat (Web site directory) the template like a Web

Tuesday, April 24th, 2007

You can treat the template like a Web page in the sense that you can type text in the template or add controls to the template. If you re not sure where a template appears in a control, type in some random descriptive text. If you re editing a Header template, for example, type in I am the Header Template. Then choose End Template Editing from the Common Tasks menu for the template. Afterwards, you ll see the control in its normal appearance, and the text you typed into the template appears within that control. A big part of using server controls in a Web site is knowing how the control looks and acts in a Web browser. And to do that, use some controls in some pages. Because you went to great trouble in Chapter 4 of this book to configure your Web site to support member logins, I ll start by looking at some of the Login controls that you can use with that foundation. ASP.NET Login Controls Visual Web Developer supports several ASP.NET 2.0 controls that you can use to manage logins through your Web pages. They only work if you ve already configured your site to support membership, as discussed in Chapter 4. You can use them in any Web Form (.aspx page). In the Toolbox for an .aspx page, you ll find all the Login controls under the Login heading, as in Figure 7-7. Here s a quick overview of what each Login control is for: Pointer: Not really a Login control. If you click a control and then change your mind and want to get back to the normal mouse pointer, click this Pointer item. 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. Figure 7-6: Common Tasks menu s Template Editing Mode. 130 Part II: Building Your Web Site
Note: If you are looking for cheap and reliable webhost to host and run your mysql application check Vision mysql hosting services

Red text in a template represents text (Web hosting account) that

Tuesday, April 24th, 2007

Red text in a template represents text that appears in the browser only under special circumstances, such as when the user fails to fill in a required text box. You don t have to change any of the red text, it s just a temporary placeholder for normal text that will appear in the Web browser. Administering the Web site The Administer Website option on the Common Tasks menu is just a shortcut to the Web Site Administration Tool discussed in Chapter 3. There s really no need to switch to that tool, though. The link is only there as a convenience in case you want to check, or maybe change, current user accounts, roles, or access rules. Editing templates The Common Tasks menu of some server controls includes an Edit Templates option. For example, the multipage CreateUserWizard template described a little later in this chapter has an Edit Templates option on its Common Tasks menu. Clicking that option takes you to a template-editing window that has its own Common Tasks menu. From the Templates Common Tasks menu, you can choose which template (that is, which portion of the control) you want to style. Figure 7-6 shows an example where I chose Edit Templates from its common tasks menu after dragging a CreateUserWizard control onto a page. Selected control Figure 7-5: Log In button selected in a template. Chapter 7: Working with ASP.NET Controls 129
Note: If you are looking for best quality webspace to host and run your tomcat application check Vision tomcat hosting services

Converting a control to a (1 on 1 web hosting) template By looking

Monday, April 23rd, 2007

Converting a control to a template By looking at the Login control shown back in Figure 7-4, you can conclude that it must be made of several smaller controls. After all, it contains text, boxes, and a button, all neatly aligned. Where are those individual controls, and what if you want to change one? The answer lies in converting the control from an individual control to a template. As its name implies, the template defines the exact content and position of each item that makes up the 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. The Reset option undoes changes you ve made to the template before converting it back to a single control. Don t click Reset if you intend to keep changes you ve made in a template. Within the template, each control has its own tiny arrow button so tiny you practically need a microscope to see it. Fortunately, you don t have to click the tiny . button. It s just there to identify the upper-left corner of each control in the template. Click anywhere on a control to select it. Figure 7-5 shows an example in which I ve clicked the Log In button in the template. To select multiple controls, click the first one, then hold down the Ctrl key as you click others. The Properties sheet, as always, shows the name and properties of the selected control. Because it s a server control, it won t have the usual HTML tag name in angle brackets. You can change any property of the control in the usual manner. For example, to change the text that appears on the selected button, change the button s Text property. Figure 7-4: Classic scheme applied to the Login1 control. 128 Part II: Building Your Web Site
Note: If you are looking for best quality webspace to host and run your tomcat application check Vision virtual web hosting services

Photo web hosting - The Style Builder won t work for all parts

Monday, April 23rd, 2007

The Style Builder won t work for all parts of an ASP.NET control. If you want to fine-tune every single element in a control, you have to convert it to a template first. This is done on the Common Tasks menu you ll find on ASP.NET server controls. This menu is explored more fully in the next few sections. Using the Common Tasks menu In Design view, when you select (click) a server control, you see a tiny arrow button somewhere on its border. Clicking that tiny button opens the control s Common Tasks menu. In Figure 7-3, for example, I ve clicked the little arrow button for a Login control on a page in Design view. The exact options on a Common Tasks menu vary from one server control type to the next. But some options, such as Auto Format Convert to Template Administer Website Edit Templates are so common they deserve further mention. The next few sections discuss these options in greater detail. Using Auto Format The easiest option on the Common Tasks menu is 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. When you click a scheme name, the preview shows you how the scheme looks. If you find a scheme you like, just click OK to select it. Or, if you don t want to use a scheme and just want to use the default control appearance, click Remove Formatting, then click OK. In Figure 7-4, I chose Auto Format.Classic scheme, and clicked OK. The Login control takes on the Classic scheme (it s blue on the screen, not gray). The change is also reflected in the control s BackColor, BorderColor, and other properties. In the Properties sheet, values in boldface are recent. This serves as a good reminder that you can Undo them with Ctrl+Z or Edit.Undo. Chapter 7: Working with ASP.NET Controls 127
Note: If you are looking for cheap webhost to host and run your apache application check Vision apache web hosting services

Tweaking server controls (Photoshop web design) in Design view In Design

Sunday, April 22nd, 2007

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. The Properties sheet in Figure 7-3 shows an example in which a Login control is selected. The name of the control is Login1. 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 sheet of Figure 7-3, System.Web.UI.WebControls.Login is the full name of the Login control within the .NET Framework namespace. You can design some elements of an ASP.NET control using the Style Builder. Just right-click the control and choose Style, or click the control so its name shows at the top of the Properties sheet. Then click the Style property and the Build button that appears. The Style Builder opens, and you can choose items as you would for any normal HTML control. For example, to change the size of the text in the Login1 control, scroll down its properties list and click the + sign next to the Font property. Then click the Size property and choose a relative size like Medium. ASP.NET controls are converted to HTML before they re sent to the server. Element styles like TABLE and TD (for table cells) are applied to the HTML automatically. So don t knock yourself out trying to design an ASP.NET control in Design view until you ve had a chance to see how it looks in a Web browser. Figure 7-3: The Login Tasks menu, showing Properties for an ASP.NET control. 126 Part II: Building Your Web Site
Note: If you are looking for cheap and reliable webhost to host and run your web application check Vision coldfusion web hosting services

The .NET Framework (Web site designers) is an enormous collection of

Sunday, April 22nd, 2007

The .NET Framework is an enormous collection of tools for programmers (and, like the world and all it contains, not a subject we have to get into right now). Suffice it to say that all ASP.NET Web server controls you find in VWD are members of the .NET Framework. And as such, complete documentation about any server control is available from the .NET Framework online documentation. 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. Adding a Server Control to a Page Adding a server control to a page is pretty simple: You drag its name from the Toolbox onto your page. You can put server controls on a blank .aspx page, in Master Pages, or in the content placeholder in a page that uses a Master Page. The size and complexity of server controls ranges from a tiny link on a page with a few properties to multipage wizards consisting of many smaller controls and many properties, and every size in between. Despite the differences among server controls, there are some commonalities in how you work with them. Those commonalities are what this chapter is mostly about. As mentioned, adding a server control to a page is simple: You just drag its name from the Toolbox to wherever you want to place it on the page. In Figure 7-2, for example, I ve created a page named Login.aspx and placed a table (along with some text) on the page. In the figure, I ve just dragged a Login control from the Toolbox into the lower-right cell of the table. Drag Figure 7-2: Using data and .aspx pages to create HTML. Chapter 7: Working with ASP.NET Controls 125
Note: If you are looking for cheap and reliable webhost to host and run your web application check Vision coldfusion web hosting services

Personal web server - Certainly Google didn t have a Web page already

Saturday, April 21st, 2007

Certainly Google didn t have a Web page already made up and waiting, just in case someone happened to search for 1966 Ford Mustang convertible parts . There are a near infinite number of word combinations that people might search for. And there s no way to create a near infinite number of Web pages to cover every conceivable combination of words people might search for. Instead, Google s Web server has to take whatever words a user submits, search its database of 8 billion or so links for pages that contain those words, then create a page that contains appropriate links to send to the user s Web browser. In other words, Google s Web server had to take an active role in creating the page it sent to your Web browser. That is the very essence of a dynamic, data-driven Web site. 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. I m not saying the Google was created with Visual Web Developer. Google was created long before Visual Web Developer existed. But the concept of having the Web server take an active role in creating a Web page is all that matters for this analogy. Likewise, we won t be building a search engine in this book. The only analogy that matters is the fact that Google s Web server plays an active role in creating the Web pages that get sent to people who conduct searches. Making your Web server take an active role in creating the pages it sends is what ASP.NET is all about. Active Server Pages (Web pages with an .aspx extension) are basically Web pages that contain Active Server Controls. But 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. Figure 7-1 illustrates the basic idea. Data + ASPX + = HTML page Web Figure 7-1: server Using data and .aspx pages to create HTML. 124 Part II: Building Your Web Site
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision best web hosting services