1 / 22

Server Control Tips & Tricks

Server Control Tips & Tricks. Presented by: Patrick Hynds Microsoft Regional Director CriticalSites CTO MCSD, MCSE+I, MCDBA, MCSA, MCP+Site Builder, MCT. Agenda. Brief Overview Render & Control Lifecycle Adding Confirm to a Button Scrollable Datagrid Composite Controls

lindsay
Download Presentation

Server Control Tips & Tricks

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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. Namespace reference Class to create ID of the instance Sets the liststyle property on l1 Marks tag as a server control Sets the Items property on l1 Tag-Based Persistence • Tags parsed at runtime • Create control instance • Set initial property values <acme:List id=l1 liststyle=number runat=server> <Items> <acme:ListItem>first item</acme:ListItem> <acme:ListItem>second item</acme:ListItem> <acme:ListItem>third item</acme:ListItem> </Items> </acme:List>

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

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

  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 <div></div> tag • Great candidate for a server control • Cleaner HTML • No messy <div> 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 • Build control project in debug mode • Set breakpoint(s) • 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. Please fill out your session evaluations! Server Control Tips & Tricks Patrick J. Hynds CTO, CriticalSites, Boston and New York Microsoft Regional Director for Boston MCSE+I, MCSD, MCDBA, MCT

More Related