1 / 13

Mo dule 8: Creating User Controls

Mo dule 8: Creating User Controls. Overview. Adding User Controls to an ASP.NET Web Form Creating User Controls. Lesson: Adding User Controls to an ASP.NET Web Form. What is a User Control? Why Use User Controls? Practice: Listing User Controls Adding a User Control

indiya
Download Presentation

Mo dule 8: Creating User Controls

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Module 8:Creating User Controls

  2. Overview • Adding User Controls to an ASP.NET Web Form • Creating User Controls

  3. Lesson: Adding User Controls to an ASP.NET Web Form • What is a User Control? • Why Use User Controls? • Practice: Listing User Controls • Adding a User Control • Demonstration: Creating a User Control

  4. What is a User Control? • User controls simplify the reuse of code and UI components within a Web application • A user control is a user-defined Web server control with an .ascx extension • Contains HTML, but not the <HTML>, <BODY>, or <FORM> tags or • Contains code to handle its own events <%@ Control Language="vb" %> <%@ Control Language="c#" %>

  5. Control1.ascx Page1.aspx Page2.aspx Why Use User Controls? • Reuse user interface and code Application A Application B Page3.aspx

  6. Practice: Listing User Controls • Students will: • List examples of when it is appropriate to use user controls • Time: 5 minutes

  7. Adding a User Control • Use the @ Register directive to include a user control in an ASP.NET Page • Insert the user control in a Web Form • Use Get and Set properties of the user control or <%@ Register TagPrefix="demo" TagName="validNum" Src="numberbox.ascx" %> <demo:validNum id="num1" runat="server"/> num1.pNum = 5 'uses Set x = num1.pNum 'uses Get num1.pNum = 5; //uses Set x = num1.pNum; //uses Get

  8. Demonstration: Creating a User Control • Create a new user control • Create a property

  9. Lesson: Creating User Controls • Creating a User Control • Demonstration: Using a User Control

  10. Creating a User Control • Two methods for user control creation: • Create a new user control using Visual Studio .NET • Convert an existing ASP.NET page to a user control • Host page interacts with the control using properties • Host page should use flow layout Public Property pNum() As Integer Get Return Convert.ToInt32(txtNum.Text) End Get Set (ByVal value As Integer) txtNum.Text = CStr(value) End Set End Property public int pNum { get { return Convert.ToInt32(txtNum.Text); } set { txtNum.Text = Convert.ToString(value); } }

  11. Demonstration: Using a User Control • Insert a user control on a page • Use the user controls in the code-behind page

  12. Review • Adding User Controls to an ASP.NET Web Form • Creating User Controls

  13. Lab 8: Creating User Controls Logon Page Login.aspx BenefitsHome PageDefault.aspx CohoWinery Page HeaderHeader.ascx ASPState Menu ComponentClass1.vb or Class1.cs Registration Register.aspx Web.config tempdb Life InsuranceLife.aspx RetirementRetirement.aspx MedicalMedical.aspx DentalDental.aspx XML Web ServicedentalService1.asmx ProspectusProspectus.aspx DoctorsDoctors.aspx User Controlnamedate.ascx Lab Web Application XML Files Doctors Dentists

More Related