1 / 11

Designing & Developing Web-Based Solutions in ASP.NET

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

Download Presentation

Designing & Developing Web-Based Solutions in ASP.NET

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. Designing & Developing Web-Based Solutions in ASP.NET Week 5 Custom Server Controls

  2. Today’s Agenda • Lecture: • Custom Server Control • Rendering • Adapters • Templates • Lab: • Rendering html Designing & Developing Web-Based Solutions in ASP.NET

  3. Custom Controls • Use and register same as User Controls • Derive from • Control • WebControl • or existing control Designing & Developing Web-Based Solutions in ASP.NET

  4. Render Methods to Override Best used from Control Best used with WebControl Designing & Developing Web-Based Solutions in ASP.NET

  5. 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

  6. 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

  7. 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

  8. 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

  9. 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

  10. 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

  11. 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

More Related