Presentation is loading. Please wait.

Presentation is loading. Please wait.

Module 8: Creating User Controls. Overview Adding User Controls to an ASP.NET Web Form Creating User Controls.

Similar presentations


Presentation on theme: "Module 8: Creating User Controls. Overview Adding User Controls to an ASP.NET Web Form Creating User Controls."— 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,, or tags or Contains code to handle its own events

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

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 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" %> Register TagPrefix="demo" TagName="validNum" Src="numberbox.ascx" %> num1.pNum = 5 'uses Set x = num1.pNum 'uses Get num1.pNum = 5 'uses Set x = num1.pNum 'uses Get 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 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); } 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 Logon Page Login.aspx Registration Register.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


Download ppt "Module 8: Creating User Controls. Overview Adding User Controls to an ASP.NET Web Form Creating User Controls."

Similar presentations


Ads by Google