user controls macdonald pp. 381-386 mis 324 mis 324 professor sandvig professor sandvig

8
User Controls User Controls MacDonald pp. 381-386 MacDonald pp. 381-386 MIS 324 Professor Sandvig

Post on 20-Dec-2015

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: User Controls MacDonald pp. 381-386 MIS 324 MIS 324 Professor Sandvig Professor Sandvig

User ControlsUser ControlsMacDonald pp. 381-386MacDonald pp. 381-386

MIS 324

Professor Sandvig

Page 2: User Controls MacDonald pp. 381-386 MIS 324 MIS 324 Professor Sandvig 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

Page 3: User Controls MacDonald pp. 381-386 MIS 324 MIS 324 Professor Sandvig Professor Sandvig

What are User Controls?What are User Controls?

Reusable UI codeReusable UI code

Classes

User Controls

Code

Interface

ReusabilityReusabilityModularityModularityEncapsulationEncapsulation

Page 4: User Controls MacDonald pp. 381-386 MIS 324 MIS 324 Professor Sandvig Professor Sandvig

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

Page 5: User Controls MacDonald pp. 381-386 MIS 324 MIS 324 Professor Sandvig Professor Sandvig

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”

Page 6: User Controls MacDonald pp. 381-386 MIS 324 MIS 324 Professor Sandvig Professor Sandvig

ImplementationImplementation

Control PropertiesControl Properties Create Class PropertyCreate Class Property Get & SetGet & Set Displayed by IntellisenseDisplayed by Intellisense See handoutSee handout

Page 7: User Controls MacDonald pp. 381-386 MIS 324 MIS 324 Professor Sandvig Professor Sandvig

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

Page 8: User Controls MacDonald pp. 381-386 MIS 324 MIS 324 Professor Sandvig Professor Sandvig

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