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? Adding 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 (.ascx.vb or.ascx.cs )

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

6 Why Use User Controls? User controls offers many advantages when developing a Web application: User controls are self contained User controls provides separate variable namespaces, which means that none of the methods and properties of user control conflict with any existing methods or properties of the hosting page. User controls can be used more than once within the hosting page, without causing property and method conflicts. User controls can be written in a different language from the main hosting page. Eg: A user control is written in C# and Web form is written in VB.NET.

7 Why Use User Controls? The examples where a user control simplifies Web page development: Text box to only accept integers in a specific range. The user control would include validation controls. Data grid control that always connects to the same data source, to display data from a stored procedure or table. Grouping of text boxes and other controls to accept mailing information ( name, address, state, city, postcode) form user. Grouping of text boxes and other controls to accept contact information (home telephone number, business telephone number, mobile telephone, e- mail address) form user.

8 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

9 Adding a User Control Use Get and Set properties of the user control to expose the values of text box to the host. or 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

10 Lesson: Creating User Controls Creating a User Control Demonstration: Using a User Control

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

12 Exercise List TWO examples where a user control simplifies Web page development. How do you access the properties of a user control’s UI elements from the host page? How do you reference a user control from an ASP.NET Web form? Can you use two different user controls with the same name in the same ASP.NET page? How can you use a user control in two different Web applications?

13 3 lab execises this week.. 1: Data binding against object (use list-bound controls) 2: Using master pages and site navigation 3: Creating and using User Control

14 List-Bound Controls What is List-Bound Controls? Def 1 :- The controls that can be populated automatically with the data from a data source Def 2:- The controls that connect to a data source and display the data.

15 Examples : -CheckBoxList- Repeater -DataGrid -DataList -DropDownList -ListBox -RadioButtonList


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