User Controls

Download Report

Transcript User Controls

User Controls
MacDonald pp. 381-386
MIS 324
Professor Sandvig
Outline
What are User Controls
Features
Implementation


Basic
Passing parameters
Example
Compared to PHP include()
Summary
What are User Controls?
Reusable UI code
Classes
Reusability
Modularity
Encapsulation
User Controls
Features
Syntax similar to .aspx page


Script tags
Page events
Reusability


Use in many .aspx page
Header, footers menus
Caching

Allows to cache parts of a page
Nesting

User controls can call other user controls
Implementation
File extension: .ascx
Register user control on .aspx page

Page directives
Initialize in code render block

Similar to web controls
<myControl:Menu id=“ucLeftMenu” runat=“server” />
Pass parameters in as properties
1. In code render block
myHeading=“Featured Product”
2. Programatically:
ucLeftMenu.Heading = “Featured Product”
Implementation
Control Properties




Create Class Property
Get & Set
Displayed by Intellisense
See handout
Implementation
Examples:

Application: MIS 324 web site
Buttons, content, search, quotes, weather
SSI for header and footer, groups of buttons

Syntax: output (source)
Moving data between .aspx & .ascx


In: No problem
Out:
Timing is an issue
Creates undesirable dependency

Solution: handle events inside .ascx
Summary
Benefits of User Controls


Reusable UI code
Encapsulation
Compartmentalize functionality


Pass in properties
Fire own set of page events
Use to fill controls from data source



Capture control events
Caching
Easy to use