of 37/37
Controls im Web ASP.NET Controls für Web Forms und MVC Daniel Fisher (lennybacon) | devcoach.com

2010 - Basta: ASP.NET Controls für Web Forms und MVC

  • View

  • Download

Embed Size (px)

Text of 2010 - Basta: ASP.NET Controls für Web Forms und MVC

  1. 1. Controls im Web ASP.NET Controls fr Web Forms und MVC Daniel Fisher (lennybacon) | devcoach.com
  2. 2. Lennybacon.com Daniel Fisher | CTO & Software Architect MCP, MCTS, MCPD [email protected] Mit-Grnder und Geschftsfhrer von devcoach.com www.devcoach.com Mit-Grnder und Vorstand der gemeinntzigen www.just community.de e.V. Veranstalter des grten Entwickler & IT-Pro Community Events in Deutschland: www.nrwconf.de Mit-Grnder und Leiter der INETA Usergroup Dsseldorf www.NetUG-NiederRhein.de Mitglied im Microsoft Community Leader & Insider Program (CLIP) Connected Systems Advisory Board Expertengruppe fr WCF, WF & BizTalk
  3. 3. Efficient Communication
  4. 4. devcoach.com Leistungen Architektur-Beratung Strukturierter und effizienter zu einer wartbaren Anwendung. Software-Entwicklung Team-out-of-the-box (Near-shoring) Objektmodelle und Datenzugriff Kommunikations-Infrastrukturen Identitts- und Berechtigungsmodelle Web 2.0 und Rich Internet Applikation Coaching & Training Technologien schneller verstehen und richtig einsetzen. Technologien Microsoft Windows & .NET Framework ASP.NET, WCF, WF, WPF, Silverlight & Geneva Kunden Versicherung, Finanzindustrie, Mittelstand, Handel, Kommunikation, Softwarehersteller u.v.a. Bundesamt fr Sicherheit in der Informationstechnologie, Microsoft, Dresdner Bank Project Experience Technology Know-how devcoach
  5. 5. Agenda Web Controls Whats MVC anyway? Recap 2006 Controls for the Microsoft Web Platform Summary
  6. 6. 7 Is all about Maintainablility! The controls concept achieves reusability for Html mark-up Server-side code Client-side scripts Compiled code that can be reused in any ASP.NET web application.
  7. 7. Controls in Code public class MyControl : Control { // }
  8. 8. Controls in Code: Usage
  9. 9. Web Form Pros
  10. 10. Web Form Cons No visual way of developing server controls, generated via code.
  11. 11. Whats MVC anyway?
  12. 12. Concepts Nice URLs & Routing Process over just add a Form Loads of naming conventions Code, Code, Code As strongly typed as possible! Once build, forever used
  13. 13. Concepts cont. No Code-Behind for ASPXs No Postbacks No Viewstate And last but not least No controls out of Redmond!
  14. 14. Web Forms or MVC?
  15. 15. Once apon a time
  16. 16. 18 Processing Child control creation CreateChildControls() All display logic OnPreRender() Rendering Custom: Render() Composite: Nothing to do?
  18. 18. First Aid Response.Redirect( http://example.org); Server.Transfer( http://example.org); link Server side only events AJAX
  20. 20. 23 Postback - Lifecycle of a control Instantiate : Constructor Initialize : OnInit method and Init Event Begin Tracking View State : TrackViewState Load View State : LoadViewState method Load Postback Data : IPostBackDataHandler.LoadPostdata method Load: OnLoad method and Load event Raise Changed Events : IPostBackDataHandler.RaisePostDataChangedEvent method Raise Postback Event : IPostBackEventHandler.RaisePostBackEvent method PreRender : OnPreRender method and PreRender event Save View State : SaveViewState method Render : Render method Unload : OnUnload method and Unload event Dispose : Dispose Method
  21. 21. 24 ViewState ViewState is used to track and restore the state values of controls that would otherwise be lost Base64 encoded - not easily readable, but not encrypted! What to store Integers Strings Floats Decimals Arrays of the data types stated above
  22. 22. Viewstate in code [Bindable(false)] [Category("Appearance")] [DefaultValue("This is the default text.")] [Description("The text of the custom control.")] public virtual string Text { get { var o = ViewState["Text"]; return o!=null ? (string) o : "This is the default text."; } set { ViewState["Text"] = value; } }
  23. 23. Viewstate in markup
  24. 24. First Aid Query Request.Form and Request.QueryString Use local fields most times they work fine!
  25. 25. PROBLEM #3: BINDING
  26. 26. Binding in code public overrride OnInit( object sender, EventArgs e) { List persons = Repository.GetAll(); myControl.DataSource = persons; myControl.DataBind() }
  27. 27. First Aid HttpContext.Current.Items Cast to ViewPage Access Model Cast to IEnumerable
  29. 29. Resources Images Java Script Styles
  30. 30. Resources in code [assembly: WebResource( "devcoach.Web.UI.Controls.Busy.gif", "image/gif")] imageUrl = Page.ClientScript.GetWebResourceUrl( GetType(), "devcoach.Web.UI.Controls.Busy.gif");
  31. 31. First Aid Embedded VirtualPathProvider Routing