user controls macdonald pp. 381-386 mis 324 mis 324 professor sandvig professor sandvig
Post on 20-Dec-2015
219 views
TRANSCRIPT
User ControlsUser ControlsMacDonald pp. 381-386MacDonald pp. 381-386
MIS 324
Professor Sandvig
OutlineOutline
What are User ControlsWhat are User Controls
FeaturesFeatures
ImplementationImplementation BasicBasic Passing parametersPassing parameters
ExampleExample
Compared to PHP include()Compared to PHP include()
SummarySummary
What are User Controls?What are User Controls?
Reusable UI codeReusable UI code
Classes
User Controls
Code
Interface
ReusabilityReusabilityModularityModularityEncapsulationEncapsulation
FeaturesFeatures
Syntax similar to .aspx pageSyntax similar to .aspx page Script tagsScript tags Page eventsPage events
ReusabilityReusability Use in many .aspx pageUse in many .aspx page Header, footers menusHeader, footers menus
CachingCaching Allows to cache parts of a pageAllows to cache parts of a page
NestingNesting User controls can call other user controlsUser controls can call other user controls
ImplementationImplementation
File extension: .ascxFile extension: .ascxRegister user control on .aspx pageRegister user control on .aspx page
Page directivesPage directives
Initialize in code render block Initialize in code render block Similar to web controlsSimilar to web controls
<myControl:Menu id=“ucLeftMenu” runat=“server” /> <myControl:Menu id=“ucLeftMenu” runat=“server” />
Pass parameters in as propertiesPass parameters in as properties1.1. In code render blockIn code render block
myHeading=“Featured Product”myHeading=“Featured Product”
2.2. Programatically:Programatically:ucLeftMenu.Heading = “Featured Product”ucLeftMenu.Heading = “Featured Product”
ImplementationImplementation
Control PropertiesControl Properties Create Class PropertyCreate Class Property Get & SetGet & Set Displayed by IntellisenseDisplayed by Intellisense See handoutSee handout
ImplementationImplementation
Examples: Examples: Application: MIS 324 web siteApplication: MIS 324 web site
Buttons, content, search, quotes, weatherButtons, content, search, quotes, weatherSSI for header and footer, groups of buttonsSSI for header and footer, groups of buttons
Syntax: output (source)Syntax: output (source)
Moving data between .aspx & .ascxMoving data between .aspx & .ascx In: No problemIn: No problem Out: Out:
Timing is an issueTiming is an issueCreates undesirable dependencyCreates undesirable dependency
Solution: handle events inside .ascxSolution: handle events inside .ascx
SummarySummary
Benefits of User ControlsBenefits of User Controls Reusable UI codeReusable UI code EncapsulationEncapsulation
Compartmentalize functionalityCompartmentalize functionality Pass in propertiesPass in properties Fire own set of page eventsFire own set of page events
Use to fill controls from data sourceUse to fill controls from data source Capture control eventsCapture control events CachingCaching Easy to useEasy to use