Steven Walther discusses how to actualize basal Web Anatomy Pages. Apprentice how to add a new Web Anatomy Folio to a activity and abridge it, how to add HTML and Web controls to your project, and how to handle both ascendancy and folio contest by abacus accident handlers to your code.
In This Chapter
In this chapter, you apprentice how to body Web Anatomy Pages. Web Anatomy Pages, clashing accepted changeless HTML pages, can accommodate activating content. You can use Web Anatomy Pages to do such things as validate anatomy abstracts and affectation and adapt database data. Web Anatomy Pages are the best important allotment of any Web Appliance that you body with Beheld Studio .NET.
In this chapter, you will learn
How to actualize a simple Web Anatomy Page
How to add server controls to a Web Anatomy Page
How to handle contest in a Web Anatomy Page
Although Web Anatomy Pages can accommodate activating content, the foundation of any Web Anatomy Folio is accepted HTML. You actualize all the changeless portions of a Web Form Folio by appliance the aforementioned methods that you abstruse about in Affiliate 2, “Using the Beheld Studio .NET Designer.”
However, Web Anatomy Pages can accommodate two things that cannot be included in changeless HTML pages. Web Anatomy Pages can accommodate server controls and application logic.
You can anticipate of server controls as server-side HTML tags. Back you add a server ascendancy to a page, the ascendancy is accomplished on your Web server and it generates agreeable that is beatific to a Web browser.
The advantage of server controls over apparent old HTML tags is that you can affairs server controls. Server controls accept properties, methods, and events that you can dispense in your code.
In this chapter, you’ll be provided with an overview of the basal server controls for architecture anatomy elements. For example, you’ll apprentice how to add Textbox and Button controls to a Web Anatomy Page.
A Web Anatomy Folio can additionally accommodate appliance logic. You can add programming cipher to a Web Anatomy Folio that executes whenever the folio is requested. For example, you can address Beheld Basal .NET cipher that retrieves abstracts from a database table and displays the abstracts in a server control.
In this chapter, you’ll apprentice how to add appliance argumentation to a Web Form Folio that handles altered folio events. For example, you’ll apprentice how to affectation altered letters on a folio depending on the options that a user selects in a form.
We’ll alpha with a simple Web Anatomy Page. We’ll actualize a folio that about displays a fortune.
You should add a Web Anatomy Folio to an absolute ASP.NET project. To apprentice how to actualize a new project, see Affiliate 1, “Getting Familiar with the Development Environment.”
First, we charge to add a Web Anatomy to a activity by accomplishing the following:
Select Project, Add Web Form.
In the Add New Item chat box, access the name Fortune.aspx for the Web Anatomy in the Name argument box.
Now that you’ve created a Web Anatomy Page, you can add server controls to the folio from the Web Forms toolbox. We’ll add a Label ascendancy to the folio by assuming the chase steps:
If the Toolbox window is not already open, baddest View, Toolbox.
Drag a Label ascendancy assimilate the Designer apparent from beneath the Web Forms tab in the Toolbox.
After you add the Label control, your awning should resemble Figure 3.1.
Figure 3.1 Abacus a Label ascendancy to a Web Anatomy Page.
The aing footfall is to add some appliance argumentation to the page. We appetite to retrieve a accidental affluence from an ArrayList of fortunes and affectation the fortune in the Label control. To do this, accomplish the afterward steps:
Double-click the Designer apparent to about-face to the Cipher Editor.
Finally, we are accessible to abridge and appearance our Web Forms page. Right-click the Web Anatomy in the Band-aid Explorer window and baddest Body and Browse. The Web Anatomy Folio will be opened in a browser and you should see a affluence (see Figure 3.2). Whenever you bang the Refresh on, a new affluence is about alleged and displayed.
If you accept an absurdity back architecture your code, baddest Body Band-aid from the Body menu. A account of errors in your cipher will pop up in the Task List window. You can double-click an absurdity to go anon to the absurdity in your code.
Figure 3.2 A Web Anatomy Folio announcement a accidental fortune.
When you actualize a Web Anatomy Page, you about charge to assignment with the folio by appliance three altered interfaces. While designing the beheld elements of a Web Anatomy Page, you use either Design Appearance or HTML Appearance with the Designer. While developing the appliance argumentation for a Web Anatomy Page, you use the Code Editor.
In reality, a Web Anatomy Folio consists of two files. One file, the presentation page, contains all the user interface elements of the Web Form, such as HTML tags and Web server controls. This book charge end with the addendum .aspx. This is the folio that you absolutely appeal back aperture the folio in your Web browser.
A Web Anatomy additionally uses a additional file, alleged the code-behind file, which contains all the appliance argumentation for the page. By default, the code-behind book does not arise in the Band-aid Explorer window. To see this file, you must baddest Show All Files from the Activity menu. The code-behind book has the same name as the presentation folio with the accession of the addendum .cs or .vb. The code-behind book ends with the addendum .cs or .vb because it is a C# or VB.NET chic file.
While alive with the user interface elements of a Web Form, you use either Design or HTML Appearance in the Designer window. To add appliance argumentation to a page, you assignment with the Cipher Editor. You can about-face amid the Designer and Code Editor by appliance any of the afterward methods:
Double-click the Designer apparent to about-face to the Cipher Editor.
Select Cipher from the Appearance card to about-face to the Cipher Editor or select Design from the Appearance card to about-face to the Designer window.
Use the keyboard shortcuts Shift F7 and F7.
In the Designer window, right-click the folio and baddest View Code.
In the Band-aid Explorer window, right-click the folio and baddest either Appearance Cipher or Appearance Designer.
Because one allotment of a Web Anatomy Folio is a C# or Beheld Basal .NET chic file, you charge abridge a Web Anatomy Folio afore you can appearance it in a Web browser. If you don’t abridge a Web Anatomy afore aperture the folio in a browser, you’ll accept the absurdity displayed in Figure 3.3.
Figure 3.3 Absurdity from examination a Web Anatomy Folio after accumulation it.
You can abridge all the files in a activity and appearance the achievement of a accurate Web Anatomy Folio by right-clicking the folio in the Band-aid Explorer window and selecting Body and Browse. The folio is aggregate and displayed in the absence Beheld Studio .NET Web browser. This will be the adopted adjustment of accumulation and examination pages acclimated in this book.
If you adopt to use the keyboard, you can body and browse the accepted page by acute Ctrl F8.
It is important to accept that there is no way to body alone a single folio in a project. Back you do a build, all files independent in the activity are compiled. This agency that back you accept any errors in any folio in a project, you cannot body any added page.
You can briefly exclude a folio from a activity by right-clicking the page in Band-aid Explorer and selecting Exclude From Project. You’ll charge to do this back the folio has an absurdity but you appetite to assignment on addition folio before acclimation it. You can balance the afar folio by selecting Show All Files from the Activity card and again right-clicking the filename and selecting Include In Project.
Alternatively, you can body all the files in a band-aid or activity without aperture a folio in a Web browser. You can baddest any one of the afterward options from the Body menu:
Build SolutionCompiles all files in all projects contained in the accepted band-aid that accept been adapted back the Body command was aftermost executed
Rebuild SolutionCompiles all files in all projects contained in the accepted solution, behindhand of whether the files accept been modified back the Body command was aftermost executed
Build Activity NameCompiles all files in a accurate project that accept been adapted back the Body command was last executed
Rebuild Activity NameCompiles all files in a particular activity that accept been adapted back the Body command was last executed
When you abridge the files in a activity appliance any of these methods, an Output window opens that displays letters generated during compilation. At the end of compilation, the Achievement window should affectation the cardinal of files that were auspiciously built.
If any errors are encountered while architecture a activity or solution, the Task window will accessible and affectation a account of the errors. You can double-click any absurdity in the Task Account to go anon to the folio absolute the error.
You additionally can abridge the files in your appliance by appliance the options amid beneath the Debug menu. Debugging is discussed in detail in Affiliate 6, “Debugging Your Web Anatomy Pages.”
9 Reliable Sources To Learn About Create Web Page Form | Create Web Page Form – create web page form
| Welcome to our blog site, on this occasion We’ll teach you about create web page form