The content of this section:
- Add an ASPX form and design the form content
- Add a style to an ASPX form
Earlier we added two C # files for the Partyinvites Application project: GuestResponse.cs and ResponseRepository.cs files. The code in these two files is the Guestresponse class used to describe the data, and the Responserepository class that is used to read and write data. None of the two classes are directly accessible to the user. Now we're going to start designing a page that interacts with the user, which is the page we usually understand.
Our next task is to create a page that includes party information and allows guests to respond.
Open the Default.aspx page file that we previously added for the Partyinvites project. Modify the code in Qing Dynasty according to the following code:
Code listing 1-6 Creating a form
The example changes the id attribute value of the form element and adds some standard HTML elements to display information about the party and to collect reply information from the user. The entire page code except for the first line is not the same as the content of the HTML page we are familiar with, the rest is the same.
From the Debug menu, choose Start Debugging (Start Debugging), or click the Internet Explorer button in the toolbar to launch the application to see the changed application. As shown in 1-7, we have created a form, but it is not beautiful.
Styling the elements in a Web form is the same as styling a regular HTML page--using CSS (cascading style sheets). To add some basic styling to your application, right-click the partyinvites item in the Solution Explorer and choose Add→style Sheet (style sheet) from the pop-up menu. Set the name to Partystyles, and then click the OK button. Visual Studio adds a new partystyles.css file to your project. Set the contents of this new file to match the CSS in Listing 1-7. Although these are very basic CSS styles, they can beautify form fields.
Code Listing 1-7 CSS styles defined in the Partystyles.css file
Use the link element to associate a CSS style with a Web form. Add a LINK element to the head section of the Default.aspx file, as shown in Listing 1-8.
Note that the example uses standard HTML elements to link files that contain standard CSS styles. After you start the application, you can see the effect of using CSS, as shown in 1-8.
"ASP 09" First ASP. NET application-Create and style a form