To demonstrate working with Web Forms and server controls, in this section you'll add a main page to the Northwind Trading Company application that includes links to pages you'll add in later chapters. In addition, you'll create a login page that you'll use in several later chapters, adding login capabilities to the application. To get started, load the Northwind.sln solution you have been working on up to this point. Follow these steps to add Main.aspx and controls to the page: -
Select Project, Add Web Form from the menu bar. -
Set Name to Main.aspx and click Open. -
Add the following controls: Control | Property | Value | Label | ID | Label1 | | Text | Northwind Traders | | Font.Bold | True | | Font.Size | Large | Hyperlink | ID | hypProducts | | Text | Products | | NavigateURL | Products.aspx | Label | ID | Label2 | | Text | Maintenance | | Font.Bold | True | | Font.Size | Small | Hyperlink | ID | hypLogin | | Text | Login | | NavigateURL | Login.aspx | LinkButton | ID | lnkLogout | | Text | Log Out | | Visible | False | Hyperlink | ID | hypEmpMaint | | Text | Employee | | NavigateURL | EmpMaint.aspx | | Visible | False | Hyperlink | ID | hypPwdChange | | Text | Change Password | | NavigateURL | PWDChange.aspx | | Visible | False | -
To set Main.aspx as the startup page, right-click Main.aspx in the Solution Explorer window and then select Set as Start Page from the context menu. -
In the Solution Explorer window, right-click Global.asax and select View Code from the context menu. Modify the Session_Start() procedure in the code window, like this: Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs) Session("LoginID") = String.Empty Session("Password") = String.Empty End Sub -
In the Solution Explorer window, double-click the Login.aspx page you created in the last chapter to load the page into the page designer. -
Change the Text property of the First Name label to Login ID. -
Change the Text property of the Last Name label to Password. -
Click the text box named txtFirst. -
Change the ID property to txtLoginID. -
Click the text box named txtLast. -
Change the ID property to txtPassword. -
Change the Textmode property to Password. -
Change the lblName label control at the bottom of the form to the name lblError. Reset the BorderStyle property to None. -
Change the Click event procedure to the following code: Private Sub btnLogin_Click( _ ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnLogin.Click Server.Transfer("Main.aspx") End Sub Finally, it's time to test your application, just to make sure the login page redirects you correctly to the main page. Follow these steps to verify that things are "hooked up" correctly: -
Press F5 to run the project. -
On the main page, click the Log In link to navigate to Login.aspx. -
On the login page, click the button to navigate back to the main page. -
Close any open pages when you're done. |