Your SlideShare is downloading. ×
  • Like
2310 b 08
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.


Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply


Published in Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads


Total Views
On SlideShare
From Embeds
Number of Embeds



Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

    No notes for slide


  • 1. Mo dule 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=&quot;vb&quot; %> <%@ Control Language=&quot;c#&quot; %>
  • 5. Why Use User Controls?
    • Reuse user interface and code
    Page3.aspx Application A Application B Page2.aspx Control1.ascx Page1.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=&quot;demo&quot; TagName=&quot;validNum&quot; Src=&quot;numberbox.ascx&quot; %> <demo:validNum id=&quot;num1&quot; runat=&quot;server&quot;/> 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 Medical Medical.aspx Benefits Home Page Default.aspx Life Insurance Life.aspx Retirement Retirement.aspx Dental Dental.aspx Dentists Doctors Doctors.aspx Doctors Logon Page Login.aspx Registration Register.aspx Coho Winery Prospectus Prospectus.aspx XML Web Service dentalService1.asmx Page Header Header.ascx ASPState tempdb Lab Web Application User Control namedate.ascx Menu Component Class1.vb or Class1.cs XML Files Web. config