110 likes | 246 Views
Designing & Developing Web-Based Solutions in ASP.NET. Week 5 Custom Server Controls. Today’s Agenda. Lecture: Custom Server Control Rendering Adapters Templates Lab: Rendering html. Custom Controls. Use and register same as User Controls Derive from Control WebControl
E N D
Designing & Developing Web-Based Solutions in ASP.NET Week 5 Custom Server Controls
Today’s Agenda • Lecture: • Custom Server Control • Rendering • Adapters • Templates • Lab: • Rendering html Designing & Developing Web-Based Solutions in ASP.NET
Custom Controls • Use and register same as User Controls • Derive from • Control • WebControl • or existing control Designing & Developing Web-Based Solutions in ASP.NET
Render Methods to Override Best used from Control Best used with WebControl Designing & Developing Web-Based Solutions in ASP.NET
Control Derived – Rendering • override void Render(HtmlTextWriteroutp) • { outp.AddAttribute(<name>,<data>) outp.AddStyleAttribute(<name>,<data>) // special outp.RenderBeginTag(HtmlTextWriterTage.Div) outp.Write(“inner elements”); outp.RenderEndTag(); • } Designing & Developing Web-Based Solutions in ASP.NET
WebControl Derived Rendering Remember to: Call Base Class • Specify begin tag in constructor • Only need to override these: • RenderContents() • AddAttributesToRender() • Auto supports styles in Vis Studio property page Designing & Developing Web-Based Solutions in ASP.NET
Adaptive Rendering • A class that overrides rendering on other controls. • Derive from: • ControlAdapter • or • WebControlAdapter • Set your class as the adapter to another control in the .browser file. Designing & Developing Web-Based Solutions in ASP.NET
CustomControls - State • Store Variables in ViewState • Variables users of your control can access • Store needed Private data in control state • Must register to use: • Page.RegisterRequiresControlState(this); • Browser cannot turn off • Data stored in key/name pairs (not like other state) Designing & Developing Web-Based Solutions in ASP.NET
CC - IPostBackDataHandler • Participate in all postbacks • Implement Interface • LoadPostData() • View updates • Update self • RaisePostDataChangedEvent() • All controls initialized on page • Can now raise custom events e.g., OnTextChanged • public event EventHandlerOnTextChanged; • Users of this control can subscribe to this event • Also several special case MUST HAVE attributes Designing & Developing Web-Based Solutions in ASP.NET
Custom Controls - Ideas • Calendar Mods • Scheduler like Outlook • Composites • Address Control • Switch between State, Prov., … based on country • Brainstorm !!! Designing & Developing Web-Based Solutions in ASP.NET
Lab – Rotatable Label (standard Horizontal) Text (Vertical) T E X T (-45 degrees) T E X T Designing & Developing Web-Based Solutions in ASP.NET