[ Pobierz całość w formacie PDF ]
.NETLab 9.2: Creating a Web Forms User ControlTopic ObjectiveTo introduce the lab.Lead-inIn this lab, you will create aWeb Forms user control thatcreates a logon screen forcustomers.Explain the lab objectives.ObjectivesAfter completing this lab, you will be able to:Create a Web Forms user control.Use a Web Forms user control on a Web Form.PrerequisitesBefore working on this lab, you must be familiar with creating Web Formapplications.ScenarioIn this lab, you will create a Web Forms user control that requests logoninformation for a customer.The control will retrieve the customer informationby means of the serviced component that you created in the previous lab.Youwill then use this control on a Web Form and test the control.Starter and Solution FilesThere are starter and solution files associated with this lab.The starter files arein the install folder\Labs\Lab092\Starter folder, and the solution files are in theinstall folder\Labs\Lab092\Solution folder.Estimated time to complete this lab: 30 minutes Module 9: Developing Components in Visual Basic.NET 55Exercise 1Creating the LogOn Web Forms User ControlIn this exercise, you will open a preexisting Web Forms application that allowsyou to logon as a customer of the system.You will create a LogOn Web Formsuser control that uses text boxes and validation controls.This user controlallows users to enter their e-mail address and password and then click a Submitbutton.To open the existing Web Forms application1.Open Visual Studio.NET.2.On the File menu, point to Open, and then click Project.3.Set the location to Error! Hyperlink reference not valid.install folder\Labs\Lab092\Ex01\Starter, click LogonControl.sln, and then click Open.To create the Web user control interface1.On the Project menu, click Add Web User Control.Rename the item toLogon.ascx, and then click Open.2.From the Web Forms tab of the Toolbox, insert the following controls, andset their property values as shown.Control Property name Property valueLabel (ID) lblEmailText E-mail:TextBox (ID) txtEmailRegularExpressionValidator (ID) revEmailErrorMessage Your e -mail addressis invalidControlToValidate txtEmailValidationExpression Browse and selectInternet E-mailAddressDisplay DynamicRequiredFieldValidator (ID) rfvEmailErrorMessage Please enter ane-mail addressControlToValidate txtEmailDisplay DynamicLabel (ID) lblPasswordText Password:TextBox (ID) txtPasswordTextMode Password56 Module 9: Developing Components in Visual Basic.NET(continued )Control Property name Property valueRequiredFieldValidator (ID) rfvPasswordErrorMessage Please enter apasswordControlToValidate txtPasswordDisplay DynamicLabel (ID) lblNotFoundText Not found messageForeColor RedVisible FalseButton (ID) btnSubmitText Submit3.Arrange your controls as shown in the following screen shot: Module 9: Developing Components in Visual Basic.NET 57To create the Web user control code1.View the Code Editor for Logon.ascx.2.Declare an event with the following signature:Public Event SubmitPressed(ByVal Email As String, _ByVal Password As String)3.Create a Click event handler for the btnSubmit event.In this method, setthe Visible property of the lblNotFound label to False, and raise theSubmitPressed event, passing the following parameters:Parameter ValueEmail txtEmail.TextPassword txtPassword.Text4.Create a DisplayMessage subroutine that accepts a single string argumentcalled Message.Within the subroutine, set the following values for thelblNotFound label.Control property ValueText MessageVisible True5.Save your project.58 Module 9: Developing Components in Visual Basic.NETExercise 2Testing the LogOn Web Forms User ControlIn this exercise, you will create a simple Web Form that uses the Logon usercontrol to get customer logon information from the user.This information willthen be passed to the serviced customer component for validation andinformation retrieval that you created in an earlier exercise.You will thenredirect the browser to a preexisting Web Form that displays a welcomemessage with the customer s first name.In case you have not completed the previous exercise, a starter project has beenprovided.To open the starter project1 [ Pobierz całość w formacie PDF ]