Server control tips tricks
Download
1 / 22

- PowerPoint PPT Presentation


  • 89 Views
  • Updated On :

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

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about '' - lindsay


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Server control tips tricks l.jpg

Server Control Tips & Tricks

Presented by:

Patrick Hynds

Microsoft Regional Director

CriticalSites CTO

MCSD, MCSE+I, MCDBA, MCSA, MCP+Site Builder, MCT


Agenda l.jpg
Agenda

  • Brief Overview

  • Render & Control Lifecycle

  • Adding Confirm to a Button

  • Scrollable Datagrid

  • Composite Controls

  • Dynamic Template Loading

  • Debugging Controls


What is an asp net control l.jpg
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


Tag based persistence l.jpg

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>


Page control processing first load l.jpg
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


Page control processing post back l.jpg
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


Render control lifecycle l.jpg
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


Slide8 l.jpg

Control Rendering

Simple Control, EventLog


Confirm alert button l.jpg
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



Derive from base controls l.jpg
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


Scrollabledatagrid l.jpg
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



Composite controls l.jpg
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()


Slide15 l.jpg

Composite Control

RequiredText


Dynamic template loading l.jpg
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



Debugging controls l.jpg
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



A look into the future l.jpg
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”


Conclusion l.jpg
Conclusion

  • Server Controls can be very useful

  • Not a technology without its complexities

  • Read MS Press book by Nikhil Kothari


Server control tips tricks22 l.jpg

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


ad