Presentation is loading. Please wait.

Presentation is loading. Please wait.

Server Control Tips & Tricks Presented by: Patrick Hynds Microsoft Regional Director CriticalSites CTO MCSD, MCSE+I, MCDBA, MCSA, MCP+Site Builder, MCT.

Similar presentations


Presentation on theme: "Server Control Tips & Tricks Presented by: Patrick Hynds Microsoft Regional Director CriticalSites CTO MCSD, MCSE+I, MCDBA, MCSA, MCP+Site Builder, MCT."— Presentation transcript:

1 Server Control Tips & Tricks Presented by: Patrick Hynds Microsoft Regional Director CriticalSites CTO MCSD, MCSE+I, MCDBA, MCSA, MCP+Site Builder, MCT

2 Agenda Brief Overview Render & Control Lifecycle Adding Confirm to a Button Scrollable Datagrid Composite Controls Dynamic Template Loading Debugging Controls

3 What Is An ASP.NET Control? Defined: –Server-side Web component –… but not limited to UI A server control is a class –Exposes properties, methods, events –Logic is encapsulated Derived from –System.Web.UI.Control or –System.Web.UI.WebControls.WebControl

4 Tag-Based Persistence Tags parsed at runtime –Create control instance –Set initial property values first item first item second item second item third item third item Class to create Marks tag as a server control Namespace reference ID of the instance Sets the liststyle property on l1 Sets the Items property on l1

5 Page/Control Processing First load Init Load PreRender SaveViewState Render Dispose Each control instantiated, set to initial state, added to control tree User code runs, tests !IsPostBack condition to data bind 1 st values CreateChildControls() ensures controls are ready to render Controls save current state (if different than initial values) Each control renders itself to the Response Pages and all controls are disposed

6 Page/Control Processing Post back Init Load PreRender SaveViewState Render Dispose Last state of the controls is restored from ViewState values Posted data (in the HTTP form) is passed to its associated control Events are fired for controls in tree order, except the event that caused the post. It’s fired last. LoadViewState Postback data Postback events

7 Render & Control Lifecycle Problem –How do you output UI Render is the dominant method –Generated output of the control –Override to control output Control Tree in Page –Everything is a control (including Page) –Control tree built and walked to output

8 Control Rendering Simple Control, EventLog

9 Confirm/Alert Button Problem –Confirm user actions –Instruct with expected behavior JavaScript pop-up dialog –Confirm user action –Alert user to information Derive from Button –Add Properties for confirm/alert –Use Attributes property

10 Confirm/Alert Button

11 Derive from Base Controls Problem –Existing functionality already built –Don’t want to ‘re-invent the wheel’ Derive from ASP.NET server controls –Add functionality or behavior –Add new properties Override Render –Base.Render –Render out derived control

12 ScrollableDataGrid Problem –Lots of data in DataGrid –Don’t want to scroll browser ScrollableDataGrid control –Composite control that wraps DataGrid –Simply adds tag Great candidate for a server control –Cleaner HTML –No messy tags in design code

13 Scrollable DataGrid

14 Composite Controls Problem –How to build more complex UI interaction –Render is possible, but… A Composite Control is –A control containing other controls –Act together to solve a common problem A Composite control must –Implement INamingContainer –Overrides CreateChildControls()

15 Composite Control RequiredText

16 Dynamic Template Loading Problem –Choose template based on conditions –Static definition is easy Templates can be dynamically loaded –Page.LoadTemplate(string template) –Template is an *.ascx file Databinding –Must explicitly set Container data type –Templates must all be in separate files

17 Dynamic Template Loading

18 Debugging Controls Problem –How to debug server controls –Cannot just ‘run’ project Steps 1.Build control project in debug mode 2.Set breakpoint(s) 3.In Visual Studio.NET: Debug | Process

19 Debugging Controls

20 A look into the future VS.Net 2005 will provide more than 70 new Server Controls Partners will (and already do) provide lots of controls that can be used in the same way as the standard controls PAG group is now providing details on how to do complex tasks well via their “Blue Bricks”

21 Conclusion Server Controls can be very useful Not a technology without its complexities Read MS Press book by Nikhil Kothari

22 Server Control Tips & Tricks Patrick J. Hynds CTO, CriticalSites, Boston and New York Microsoft Regional Director for Boston MCSE+I, MCSD, MCDBA, MCT Please fill out your session evaluations!


Download ppt "Server Control Tips & Tricks Presented by: Patrick Hynds Microsoft Regional Director CriticalSites CTO MCSD, MCSE+I, MCDBA, MCSA, MCP+Site Builder, MCT."

Similar presentations


Ads by Google