Creating A Basic Web Page in Visual Web Developer
Creating A Basic Web Page in Visual Web Developer
This walkthrough provides you with an introduction to Microsoft Visual Web Developer. It guides you through creating
a simple page by using Visual Web Developer, illustrating the basic techniques of creating a new page, adding
controls, and writing code.
Prerequisites
In order to complete this walkthrough, you will need:
• Visual Web Developer
• The .NET Framework
For this walkthrough, you will create a file system Web site that does not require that you work with Microsoft
Internet Information Services (IIS). Instead, you will create and run your page in the local file system.
A file system Web site is one that stores pages and other files in a folder that you choose somewhere on your local
computer. Other Web site options include a local IIS Web site, which stores your files in a subfolder of the local IIS
root (typically, \Inetpub\Wwwroot\). An FTP site stores files on a remote server that you gain access to across the
Internet by using File Transfer Protocol (FTP). A remote site stores files on a remote server that you can access
across a local network. For more information, see Walkthrough: Editing Web Sites with FTP in Visual Web Developer.
Also, web site files can be stored in a source control system such as Visual SourceSafe. For more information, see
Introducing Source Control.
http://www.maadiguide.com [email protected]
جميع خدمات النترنت
تصميم صفحات – لوجو – دومان – إيواء – بريد إليكترونى
http://www.maadiguide.com [email protected]
جميع خدمات النترنت
تصميم صفحات – لوجو – دومان – إيواء – بريد إليكترونى
http://www.maadiguide.com [email protected]
جميع خدمات النترنت
تصميم صفحات – لوجو – دومان – إيواء – بريد إليكترونى
Note
You can rearrange and resize the windows to suit your preferences. The
View menu allows you to display additional windows.
http://www.maadiguide.com [email protected]
جميع خدمات النترنت
تصميم صفحات – لوجو – دومان – إيواء – بريد إليكترونى
1. Close the Default.aspx page. To do this, right-click the tab containing the file name and select Close.
2. In Solution Explorer, right-click the Web site (for example, C:\BasicWebSite), and then click Add New
Item.
3. Under Visual Studio installed templates, click Web Form.
4. In the Name box, type FirstWebPage.
5. In the Language list, choose the programming language you prefer to use (Visual Basic, C#, or J#).
When you created the Web site, you specified a default language. However, each time you create a new page
or component for your Web site, you can change the language from the default. You can use different
programming languages in the same Web site.
6. Clear the Place code in separate file check box. The following screen shot shows the Add New Item
dialog box.
Add New Item dialog box
In this walkthrough, you are creating a single-file page with the code and HTML in the same page. The code
for ASP.NET pages can be located either in the page or in a separate class file. To learn more about keeping
the code in a separate file, see Walkthrough: Creating a Basic Web Page with Code Separation in Visual Web
Developer.
7. Click Add.
Visual Web Developer creates the new page and opens it in Source view.
http://www.maadiguide.com [email protected]
جميع خدمات النترنت
تصميم صفحات – لوجو – دومان – إيواء – بريد إليكترونى
In this part of the walkthrough, you will add some static text to the page.
http://www.maadiguide.com [email protected]
جميع خدمات النترنت
تصميم صفحات – لوجو – دومان – إيواء – بريد إليكترونى
The page is displayed in the browser. Although the page you created has an extension of .aspx, it currently
runs like any HTML page.
Note
http://www.maadiguide.com [email protected]
جميع خدمات النترنت
تصميم صفحات – لوجو – دومان – إيواء – بريد إليكترونى
If the browser displays a 502 error or an error indicating that the page
cannot be displayed, you might need to configure your browser to
bypass proxy servers for local requests. For details, see How to: Bypass
a Proxy Server for Local Web Requests.
2. Close the browser.
You will now add server controls to the page. Server controls, which include buttons, labels, text boxes, and other
familiar controls, provide typical form-processing capabilities for your ASP.NET Web pages. However, you can
program the controls with code that runs on the server, not the client.
http://www.maadiguide.com [email protected]
جميع خدمات النترنت
تصميم صفحات – لوجو – دومان – إيواء – بريد إليكترونى
Visual Web Developer offers you various ways to set the properties of controls on the page. In this part of the
walkthrough, you will set properties in both Design view and Source view.
http://www.maadiguide.com [email protected]
جميع خدمات النترنت
تصميم صفحات – لوجو – دومان – إيواء – بريد إليكترونى
4. Select ForeColor and then type an equal sign (=). IntelliSense displays a list of colors.
Note
You can display an IntelliSense drop-down list at any time by pressing
CTRL+J.
5. Select a color for the Label control's text.
The ForeColor attribute is completed with the color that you have selected.
Note
http://www.maadiguide.com [email protected]
جميع خدمات النترنت
تصميم صفحات – لوجو – دومان – إيواء – بريد إليكترونى
4. Finish the Click event handler for the button so that it reads as shown in the following code example.
Visual Basic
Protected Sub Button1_Click(ByVal sender As Object, ByVal e
As System.EventArgs)
Label1.Text = Textbox1.Text & ", welcome to Visual Web
Developer!"
End Sub
C#
http://www.maadiguide.com [email protected]
جميع خدمات النترنت
تصميم صفحات – لوجو – دومان – إيواء – بريد إليكترونى
Note
If you are using Visual Basic with code separation, Visual Web Developer
does not add an explicit OnClick attribute. Instead, the event is bound
to the handler method using a Handles keyword on the handler
declaration itself.
In this section, you will add a Calendar control to the page and format it.
http://www.maadiguide.com [email protected]
جميع خدمات النترنت
تصميم صفحات – لوجو – دومان – إيواء – بريد إليكترونى
http://www.maadiguide.com [email protected]
جميع خدمات النترنت
تصميم صفحات – لوجو – دومان – إيواء – بريد إليكترونى
4. From the Select a scheme list, select Simple and then click OK.
5. Switch to Source view.
You can see the <asp:Calendar> element. This element is much longer than the elements for the simple
controls you created earlier. It also includes subelements, such as <WeekEndDayStyle>, which represent
various formatting settings. The following screen shot shows the Calendar control in Source view.
Calendar control in Source view
http://www.maadiguide.com [email protected]
جميع خدمات النترنت
تصميم صفحات – لوجو – دومان – إيواء – بريد إليكترونى
Visual Basic
Protected Sub Calendar1_SelectionChanged(ByVal sender As
Object, ByVal e As System.EventArgs)
Label1.Text = Calendar1.SelectedDate.ToString()
End Sub
http://www.maadiguide.com [email protected]
جميع خدمات النترنت
تصميم صفحات – لوجو – دومان – إيواء – بريد إليكترونى
C#
protected void Calendar1_SelectionChanged(object sender,
System.EventArgs e)
{
Label1.Text = Calendar1.SelectedDate.ToString();
}
Next Steps
This walkthrough has illustrated the basic features of the Visual Web Developer page designer. Now that you
understand how to create and edit a Web page in Visual Web Developer, you might want to explore other features.
For example, you might want to:
• Learn more about how to edit HTML in Visual Web Developer. For details, see Walkthrough: Basic HTML Editing
in Visual Web Developer.
• Add data access to Web pages. For details, see Walkthrough: Basic Data Access in Web Pages.
• Learn about the debugger for Web pages. For details, see Walkthrough: Debugging Web Pages in Visual Web
Developer.
• Create Web pages that are specifically designed for mobile phones and other devices. For details, see
Walkthrough: Creating Web Pages for Mobile Devices.
• Create a consistent site layout using master pages. For details, see Walkthrough: Creating and Using ASP.NET
Master Pages in Visual Web Developer.
• Add navigation to your site so users can easily move between pages. For details, see Walkthrough: Adding Site
Navigation to a Web Site.
http://www.maadiguide.com [email protected]
جميع خدمات النترنت
تصميم صفحات – لوجو – دومان – إيواء – بريد إليكترونى
The Microsoft Visual Web Developer Web development tool provides a rich HTML editing experience that lets you
work in WYSIWYG mode for visualizing Web pages and also lets you work directly with HTML markup for finer
control. This walkthrough introduces you to the HTML editing features of Visual Web Developer.
Prerequisites
In order to complete this walkthrough, you will need the following:
• A general understanding of Visual Web Developer.
For an introduction to creating Web pages in Visual Web Developer, see Walkthrough: Creating a Basic Web Page in
Visual Web Developer.
In this walkthrough, you will work with a Web site and a single ASP.NET Web page that is similar to the one that is
created in Walkthrough: Creating a Basic Web Page in Visual Web Developer. If you have completed that
walkthrough, you can use that Web site and page.
Design view displays your page in a way that is similar to how it will appear in a browser, with some differences. The
first difference is that in Design view, the text and elements are editable. The second difference is that to help you
edit your pages, Design view displays some elements and controls that will not appear in the browser. Additionally,
some elements, such as HTML tables, have a special Design view rendering that adds additional space for the editor.
Overall, Design view helps you visualize your page, but it is not an exact representation of how the page will render
in a browser.
http://www.maadiguide.com [email protected]
جميع خدمات النترنت
تصميم صفحات – لوجو – دومان – إيواء – بريد إليكترونى
Note
You can also add a control by double-clicking it.
3. Drag a Button control onto the page.
The TextBox and Button controls are ASP.NET Web server controls, not HTML elements.
4. On the Layout menu, click Insert Table.
The Insert Table dialog box appears.
5. Click OK.
http://www.maadiguide.com [email protected]
جميع خدمات النترنت
تصميم صفحات – لوجو – دومان – إيواء – بريد إليكترونى
The Insert Table dialog box provides options for configuring the table that you are creating. However, for
this walkthrough, you can use a default table layout.
Creating Hyperlinks
Design view provides builders and other tools to help you create HTML elements that require property settings.
To create a hyperlink
1. In the text This page is powered by ASP.NET., highlight ASP.NET to select it.
2. On the Format menu, click Convert to Hyperlink.
The Hyperlink dialog box appears.
3. In the URL box, type http://www.asp.net.
4. Click OK.
Note
You can run pages in several ways. If you press CTRL+F5, Visual Web
http://www.maadiguide.com [email protected]
جميع خدمات النترنت
تصميم صفحات – لوجو – دومان – إيواء – بريد إليكترونى
The editor also helps you when you type markup manually. For example, the editor provides context sensitive
choices finishing HTML tags and attributes as you type. The editor also provides error and warning information on
markup by underlining questionable markup with a wavy line. The error or warning information is available by
positioning the mouse over the markup text.
<a href="Default.aspx">Home</a>
6. Position the insertion point in the a tag.
http://www.maadiguide.com [email protected]
جميع خدمات النترنت
تصميم صفحات – لوجو – دومان – إيواء – بريد إليكترونى
<asp:Button
id="Button1"
runat="server"
Font-Bold="True"
ForeColor="Blue"
Text="Click Here" />
2. Notice that after you indent the first attribute, if you press ENTER in the tag, subsequent lines are indented to
match.
3. Switch to Design view.
4. Right-click the new Button control, and then click Copy.
5. Position the insertion point below the new Button control, right-click, and then click Paste.
This creates a button with the ID of Button2.
6. From the Standard group in the Toolbox, drag a third Button control onto the page, which creates
<Button3>.
7. Switch to Source view.
Notice that <Button2> is formatted exactly the way that you formatted <Button1>. On the other hand,
<Button3> is formatted using the default formatting for asp:button elements.
Note
For more information on how to customize the formatting of individual
elements, see Walkthrough: Advanced HTML Editing in Visual Web
Developer.
http://www.maadiguide.com [email protected]
جميع خدمات النترنت
تصميم صفحات – لوجو – دومان – إيواء – بريد إليكترونى
8. Edit the document so that <Button1> and <Button2> are on the same line without a space between them:
To start, add more elements to the page so that you will be able to examine navigation features.
To add elements
1. Switch to Design view.
2. From the HTML group in the Toolbox, drag a Table control into a cell of the table that you created in
"Working in Source View," earlier in this walkthrough.
3. From the Standard group in the Toolbox, drag a Button control into the middle cell of the nested table.
With several nested elements on the page, you can see how Document Outline provides quick navigation to any tag
in the page.
http://www.maadiguide.com [email protected]
جميع خدمات النترنت
تصميم صفحات – لوجو – دومان – إيواء – بريد إليكترونى
The tag navigator provides information about the currently selected tag and where it is in the page hierarchy.
Note
You can click to select either the tag or its contents by using the drop-
down list in the tag navigator tag. By default, clicking a tag in the tag
navigator selects the tag and its contents.
You can also use the tag navigator to help you move or copy elements.
Formatting Text
• The Formatting toolbar applies inline styles for most settings. Bold and italic formatting is applied by using the
b and i tags. Paragraph formatting is applied a block tag, such as p (for normal), pre (for formatted), and so
on. Paragraph alignment is applied by using inline styles to conform with XHTML 1.1 standards.
• The designer also lets you create a style block and a link to a cascading style sheet. For more information, see
Walkthrough: Working with Cascading Style Sheet Styles in Visual Web Developer.
• By default, the editor creates markup that is compatible with the XHTML 1.1 standard and converts all HTML
tag names to lowercase, even if you type them in uppercase. The editor also encloses attribute (property)
values in quotation marks. For more information, see Walkthrough: Advanced HTML Editing in Visual Web
Developer.
http://www.maadiguide.com [email protected]
جميع خدمات النترنت
تصميم صفحات – لوجو – دومان – إيواء – بريد إليكترونى
2. In the Options dialog box, expand Text Editor, expand HTML, and then click Validation.
3. In the Target list, enter a validation type.
Next Steps
This walkthrough has given you an overview of the HTML capabilities of the Web page editor. This includes how to
create HTML in Design view and Source view, basic formatting, and navigation. You might want to learn more about
the editing facilities in Visual Web Developer. For example, you might want to do the following:
• Learn about the additional capabilities of the HTML editor, including custom formatting options, outlining, and
HTML validation. For more information, see Walkthrough: Advanced HTML Editing in Visual Web Developer.
• Learn how to work with cascading style sheet styles. For more information, see Walkthrough: Working with
Cascading Style Sheet Styles in Visual Web Developer .
http://www.maadiguide.com [email protected]
جميع خدمات النترنت
تصميم صفحات – لوجو – دومان – إيواء – بريد إليكترونى
The Microsoft Visual Web Developer Web development tool provides a rich HTML editing experience for creating Web
pages. This walkthrough introduces some of the more advanced HTML editing features of Visual Web Developer.
Note
For an introduction to HTML editing, see Walkthrough: Basic HTML
Editing in Visual Web Developer.
Tasks illustrated in this walkthrough include the following:
• Specifying options for how the HTML editor formats elements in the page.
• Selecting options so that the HTML editor that you create is compatible with specific browsers.
• Outlining your page — that is, creating collapsible regions in the editor to reduce clutter.
Prerequisites
In order to complete this walkthrough, you will need:
• A general understanding of working in Visual Web Developer.
For an introduction to Visual Web Developer, see Walkthrough: Basic HTML Editing in Visual Web Developer.
Note
By default, Visual Web Developer creates ASP.NET Web pages using the
code-behind model. For more information, see ASP.NET Web Page Code
http://www.maadiguide.com [email protected]
جميع خدمات النترنت
تصميم صفحات – لوجو – دومان – إيواء – بريد إليكترونى
Model. In this walkthrough, you will not be using the code-behind page.
Formatting Markup
The HTML editor provides a variety of options to help you format the markup in your pages according to your own
preferences. Formatting options include the following:
• Whether tag and attribute names are in uppercase or lowercase letters. You can specify options separately for
HTML tags and ASP.NET Web server controls.
• Whether attributes are added by enclosing them in quotation marks.
• Whether elements are closed automatically by the editor. Choices include creating self-closing tags (for
example, <br />), creating opening and closing tags (<p></p>), and automatically inserting closing tags.
• How child elements of a tag are indented.
• Where line breaks are positioned around tags.
Regardless of what formatting options you set, an important feature of HTML formatting is that you have ultimate
control over the layout and appearance of the markup in the page. You can format elements manually (for example,
by indenting them), and the editor leaves your formatting as is unless you explicitly make a request to have the
markup reformatted.
In this part of the walkthrough, you will explore different formatting options and see the effect of different settings.
You will also learn how to apply formatting to the whole page or to a selection within the page.
Note
This walkthrough reviews only the formatting features that are unique to
working with HTML. As a Visual Web Developer text editor, the HTML
editor also supports various options that apply to all text editing, such
as setting tab size and line wrap. For information about general text
editing options, see Editing Text, Code, and Markup.
In this part of the walkthrough, you will add some simple HTML to the page, change formatting options, and then
add more HTML. This illustrates how changing the settings affects how the HTML is formatted.
http://www.maadiguide.com [email protected]
جميع خدمات النترنت
تصميم صفحات – لوجو – دومان – إيواء – بريد إليكترونى
By default, the designer creates elements in which the tag and attribute names are lowercase and attributes
are enclosed in quotation marks.
<IMG src=graphic.gif
6. Because you disable the Insert attribute value quotes when typing option in the preceding procedure,
the editor does not automatically enclose the attribute in quotation marks.
Note
The editor inserts quotation marks, regardless of the options setting, if
the attribute requires them, such as when an attribute value contains a
space.
http://www.maadiguide.com [email protected]
جميع خدمات النترنت
تصميم صفحات – لوجو – دومان – إيواء – بريد إليكترونى
7. Type a slash mark (/) and a right angle bracket (>) to close the <img> tag.
As noted earlier in this section, the formatting options that you set were not applied to existing markup in the page.
However, if you want, you can apply formatting settings to the page or to individual elements in the page.
Note
The editor does not remove quotation marks, even if you change the
option setting. Similarly, the editor does not change the termination of
existing tags, even if you change the option for how to close tags.
You can see from this example how formatting works in the HTML editor. When you use editing tools, such as Toolbox
or Properties, to edit elements, the editor uses the current set of formatting options to generate the markup.
However, the editor does not change any existing markup. If you want to apply new formatting options to existing
markup, you can apply it manually by using the Edit menu commands.
Note
Tag-specific formatting rules that you specify can be overridden by the
rule that the HTML editor will not change the rendering of tags. If a tag
formatting rule would change the way a tag is rendered, the rule is
ignored.
In this part of the walkthrough, you will set several tag formatting options and see how the editor works with them.
Up to this point, you have worked with HTML elements, such as the <table> element. Now, you will work with some
ASP.NET server controls, so that you can see that formatting options apply equally to controls and elements.
You will start by setting some options that apply to all tags of a certain type. You can set options for the following
types of elements:
• HTML elements that do not have content, such as br and input.
• HTML elements that can have content, such as table and span.
• Server elements (asp:) that cannot have content, such as asp:image.
http://www.maadiguide.com [email protected]
جميع خدمات النترنت
تصميم صفحات – لوجو – دومان – إيواء – بريد إليكترونى
For the first part of this section, you will add an HTML table. You will then change the tag formatting rules for table
elements and reformat the document to see the effect of changing the formatting rule.
<table>
<tr>
<td>
</td>
</tr>
5. In a blank part of the window, right-click, and then click Formatting and Validation.
6. Click Tag specific options.
7. Expand Default Settings.
A list of tag types appears, starting with Client tag does not support contents. By selecting an item in the
list, you can set different options for client and server elements, for elements that have content (such as a
table element), and for elements that do not (such as an img element).
8. Click Client tag supports contents.
Notice that the default setting is that tags use a separate closing tag and that the tags have line breaks
before, within, and after the tag.
9. Expand Client HTML tags.
10. Click td.
You will set options to change how td tags are formatted.
11. In the Line breaks list, click None.
12. Click OK to close the Tag Specific Options dialog box, and then click OK to close the Options dialog box.
13. On the Edit menu, click Format Document.
The document is reformatted. The <td> tags in the table that you added are placed in a single line:
<table>
<tr>
<td></td><td></td><td></td>
http://www.maadiguide.com [email protected]
جميع خدمات النترنت
تصميم صفحات – لوجو – دومان – إيواء – بريد إليكترونى
You can work with tag-specific options for an ASP.NET server control.
http://www.maadiguide.com [email protected]
جميع خدمات النترنت
تصميم صفحات – لوجو – دومان – إيواء – بريد إليكترونى
Notice that the <asp:ListItem> elements are all on one line. The </asp:ListBox> element appears on the
next line because tag wrapping is set to 80 characters. You can modify this value in the Options dialog box.
Although you worked with only two controls and changed only one formatting option (line breaks), you can see how
to apply options to any element that you typically work with.
Outlining Elements
In Source view, you can outline elements (collapse and expand them) so that they are out of your way when you are
not working with them. This is particularly useful for elements such as tables, which often take up a lot of space. You
can also use the collapse feature for any elements in the page.
To outline elements
1. Switch to Source view.
2. Select one of the tables that you added earlier.
• If you no longer have the tables, from the HTML group in the Toolbox, drag one onto the page.
3. On the Edit menu, point to Outlining, and then click Hide Selection.
The <table> tag is collapsed and a plus sign (+) is displayed in the margin.
4. Click the plus sign to expand the table element.
You can also configure elements so that the plus (+) and minus (-) signs appear automatically in the margin when
the elements exceed a certain size.
Validating HTML
The HTML editor can validate your HTML or make sure that it complies with the rules for specific browsers or
standards, such as XHTML. For example, the editor can find tags and attributes that are not accepted by Netscape
Navigator 4.0 or that do not comply with XHTML standards.
In this part of the walkthrough, you will work with different schemas (browser types or standards) and introduce
various types of small errors to see how the editor flags the errors.
<font face=arial>
http://www.maadiguide.com [email protected]
جميع خدمات النترنت
تصميم صفحات – لوجو – دومان – إيواء – بريد إليكترونى
Note
The Formatting and Validation command is available only in Source
view.
2. In the Options dialog box, click Validation.
Notice that regardless of whether you select or clear the Show errors check box, the error display for check
boxes is not enabled. This is because the current schema is XHTML, which already shows you all possible
validation errors.
3. In the Target list, click Internet Explorer 6.
4. Make sure that the Show errors check box is selected, and then under Show errors, select all check boxes.
5. Click OK to return to the editor.
6. Select the HTML that you entered in the preceding procedure, and then on the Edit menu, click Make
Uppercase.
After a brief pause, the tag names are underlined. When you rest the mouse pointer over a tag name, a
ToolTip indicates that the name contains uppercase letters. Generally, Internet Explorer 6 allows for
http://www.maadiguide.com [email protected]
جميع خدمات النترنت
تصميم صفحات – لوجو – دومان – إيواء – بريد إليكترونى
uppercase tag names, but you now see this validation error because you have changed the validation options
for that schema.
Validation can find many other types of errors also, such as duplicated control IDs, crossed opening and closing tags
(for example, <b><i></b></i>), and so on. However, validation in the editor does not prevent you from creating
any HTML code that you want. Validation just identifies markup that does not comply with the rules for the specified
browser.
You should understand that when an ASP.NET page runs, the resulting output consists not only of the HTML elements
that you create, but also of the HTML that is rendered by ASP.NET server controls and any code that writes to the
page. Validation cannot examine the output of those dynamic elements; that is, the editor cannot examine the
validity of generated output. By default, ASP.NET controls generate output that complies with XHTML 1.1 standards.
This means that the output is suited for most browsers. For more information about the markup that is generated by
ASP.NET controls, see ASP.NET and XHTML.
Next Steps
This walkthrough has introduced you to some of the more advanced features of the HTML editor. Although the
walkthrough did not illustrate every feature, you have seen how formatting options, outlining, and validation can
help you produce well-formed, custom-formatted markup, although still giving you final control over the markup.
Visual Web Developer
Walkthrough: Working with Cascading Style Sheet Styles in Visual Web
Developer
The Microsoft Visual Web Developer Web development tool gives you complete support for creating and applying
styles to the text, elements, and controls on Web pages.
Note
In addition to explicitly setting styles and style sheet references in a
page, you can use ASP.NET themes to set the overall appearance of the
pages in your site. For detailed information, see ASP.NET Themes and
Skins Overview.
Prerequisites
In order to complete this walkthrough, you will need the following:
• Visual Web Developer and the .NET Framework.
• A general understanding of working in Microsoft Visual Studio.
For an introduction to Visual Studio, see Walkthrough: Creating a Basic Web Page in Visual Web Developer.
http://www.maadiguide.com [email protected]
جميع خدمات النترنت
تصميم صفحات – لوجو – دومان – إيواء – بريد إليكترونى
If you have already created a Web site in Visual Studio by completing Walkthrough: Creating a Basic Web Page in
Visual Web Developer, you can use that Web site and go to the next section. Otherwise, create a new Web site and
page by following these steps.
Adding Controls
The next step is to add some controls to the page. The code will be simple, but enough to let you add breakpoints
later.
To add controls
1. Switch to Design view.
2. From the Standard group in the Toolbox, drag the following controls onto the page and set their properties
as follows:
a. Control b. Properties
http://www.maadiguide.com [email protected]
جميع خدمات النترنت
تصميم صفحات – لوجو – دومان – إيواء – بريد إليكترونى
Text: (empty)
Note
For this walkthrough, the layout of the page is not
important.
From these few steps, you can see that the Style Builder lets you set any inline style for any element without
requiring that you know the syntax.
If you prefer working directly with HTML, you can also set styles in Source view.
http://www.maadiguide.com [email protected]
جميع خدمات النترنت
تصميم صفحات – لوجو – دومان – إيواء – بريد إليكترونى
Note
The editor always puts quotation marks around the style attribute,
regardless of the formatting options that you have set. For detailed
information, see Walkthrough: Advanced HTML Editing in Visual Web
Developer.
3. Double-click background-color, and then type a colon (:).
Microsoft IntelliSense functionality displays a list of color names. A ToolTip displays the syntax for the
background-color style setting.
4. Double-click Blue, type a semicolon (;), which is the delimiter between style settings, and then press
SPACEBAR to display IntelliSense functionality.
5. Double-click color, type a colon (:), and then double-click a contrasting color, such as Yellow or White.
6. To see the effect of your choices, switch to Design view.
In this section of the walkthrough, you will create a style sheet, which lets you use the same tools that you used to
set inline styles. You will then apply the style sheet to the page that you have been editing.
Note
Be sure to select a color that is different from the default color of the
pages in the Web site.
6. Click Background, click a dark color, such as Maroon, that contrasts with the font color you selected in the
preceding step, and then click OK to close the Style Builder- body dialog box.
7. Position the insertion pointer after the closing brace of the body element, right-click, and then click Add
Style Rule.
The Add Style Rule dialog box appears.
http://www.maadiguide.com [email protected]
جميع خدمات النترنت
تصميم صفحات – لوجو – دومان – إيواء – بريد إليكترونى
The Add Style Rule dialog box lets you create new styles that are bound to a particular HTML element type,
to a style class name, or to a specific element.
8. Click Class name, and then in the box, type reverse.
This will create a new style class named .reverse. You will be able to apply the style settings that you
defined for .reverse to any element on your page. You could optionally create the class so that it applies to
only specific types of elements (anchors, buttons, and so on), but in this walkthrough you will create a simple
style class.
9. Click OK to close the Add Style Rule dialog box.
10. Use the style builder or IntelliSense functionality to set the colors for the .reverse style to the opposite of
the styles for the body. The element will look similar to the following:
.reverse
{
background-color:white;
color:maroon;
}
Now that you have a style sheet, you can reference it in the page you have been editing.
http://www.maadiguide.com [email protected]
جميع خدمات النترنت
تصميم صفحات – لوجو – دومان – إيواء – بريد إليكترونى
body
{
background-color:white;
color:Black;
}
.reverse
{
background-color:Black;
color:White;
}
4. Save the new style sheet.
In your original page, you can now add the ability to switch style sheets. You will add two radio buttons that let the
user select between a dark look and a light look.
Note
The layout of the RadioButton controls is not important for this
walkthrough.
4. Set the following properties for the RadioButton controls.
a. Control b. Properties
http://www.maadiguide.com [email protected]
جميع خدمات النترنت
تصميم صفحات – لوجو – دومان – إيواء – بريد إليكترونى
GroupName: grpSelectStylesheet
Text: Dark
Visual Basic
Sub SwitchStylesheets(ByVal sender As Object, _
ByVal e As System.EventArgs)
If radioDark.Checked Then
stylesheet.Href = "dark.css"
ElseIf radioLight.Checked Then
stylesheet.Href = "light.css"
End If
End Sub
C#
void SwitchStylesheets(Object sender, EventArgs e)
{
if(radioDark.Checked)
stylesheet.Href = "dark.css";
if(radioLight.Checked)
stylesheet.Href = "light.css";
}
8. The code determines which option button is selected and sets the Href attribute of the <link> element,
which you named stylesheet, appropriately.
9. Switch to Design view.
10. Click radioLight, and in Properties, click the events icon.
11. In the CheckedChanged box, click SwitchStylesheets.
http://www.maadiguide.com [email protected]
جميع خدمات النترنت
تصميم صفحات – لوجو – دومان – إيواء – بريد إليكترونى
This binds the CheckedChanged event of the radioLight control to the handler that you have already
written to switch style sheets. Both radio buttons will call the same handler when they are clicked.
Next Steps
This walkthrough has illustrated the basic techniques for working with CSS styles in your ASP.NET Web pages. You
might also want to explore the following ways you can control the appearance of the Web pages:
• Setting style information programmatically for HTML elements.
For detailed information, see How to: Set HTML Server Control Properties Programmatically.
• Creating styles programmatically and applying the styles to ASP.NET server controls.
For detailed information, see Customizing the Appearance of ASP.NET Server Controls Using Styles (Visual
Studio).
• Creating themes and skins, which let you specify not only CSS styles, but virtually any property of an ASP.NET
control.
For details, see ASP.NET Themes and Skins Overview.
http://www.maadiguide.com [email protected]