1 / 15

ASP .NET 2.0 : Création de contrôles serveurs

Présenté par Pierre Lagarde pierlag@microsoft.com Relation Développeurs Microsoft France. ASP .NET 2.0 : Création de contrôles serveurs. Level 300. Deux visions de l’approche composant. L’approche Contrôle Utilisateur (UserControl)

hop-wells
Download Presentation

ASP .NET 2.0 : Création de contrôles serveurs

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. Présenté par Pierre Lagarde pierlag@microsoft.com Relation Développeurs Microsoft France ASP .NET 2.0 : Création de contrôles serveurs Level 300

  2. Deux visions de l’approche composant • L’approche Contrôle Utilisateur (UserControl) • Créer une pagelet réutilisable (*.ascx) dans le designer graphique •  Facile à développer •  Pas multi-projet • L’approche Contrôle Server (CustomControl) • Créer un composant .NET Web réutilisable depuis la toolbox • Modèle compilé dans une dll •  Multi-projet •  Pas facile à développer

  3. L’approche Contrôle Server • Identifié par un tag dans le flux aspx • <asp:button …> • Les contrôles serveurs peuvent : • Générer un flux HTML vers le client dans la méthode Render • writer.RenderBeginTag(HtmlTextWriterTag.Span); • Générer du script client (cas des contrôles Validators) • RegisterClientScriptBlock • Adapter leur rendu aux différents clients • Mobile / IE / Firefox

  4. La nouvelle Architecture des Contrôles Control (1.x) WebControl (1.x) BaseDataList (1.x) BaseDataBoundControl DataBoundControl HierarchicalDataBoundControl TreeView ListControl CompositeDataBoundControl BulletedList DetailsView Menu CheckBoxList FormView DropDownList GridView ListBox RadioButtonList

  5. 2 : Mon premier contrôle serveur demo <span style="font-size:XX-[Large / Small]"> Test Phrase </span>

  6. Sauvegarde des propriétés • Le contrôle serveur est créé à chaque génération de page il faut donc implémenter un mécanisme de sauvegarde des données • Utilisation du ViewState public bool LargeText { get { object o = ViewState["LargeText"]; if (o == null) return _largeText; else return (bool)o; } set { _largeText = value; ViewState["LargeText"] = _largeText; } }

  7. Visibilité des propriétés dans l’inspecteur d’objet • Utilisation des attributs sur les propriétés [Bindable(true), Category("Appearance"), DefaultValue("true")] public bool LargeText { … } [EditorBrowsable(EditorBrowsableState.Never), DefaultValue(false)] public override bool Visible { … }

  8. 3 : Modifier mon premier contrôle demo

  9. Contrôle invisible • Réaliser un contrôle visible par Visual Studio mais invisible dans la page HTML • Utilisation des « ControlDesigner » [DesignerAttribute(typeof(InvisibleControlControlDesigner))] public class InvisibleControl : Control { … } public class InvisibleControlControlDesigner : ControlDesigner { public override string GetDesignTimeHtml() { return base.CreatePlaceHolderDesignTimeHtml();} }

  10. 4 : Contrôle Invisible demo

  11. Ajout de fonctionnalités à un contrôle existant • Créer un DropDownList multicolore <html> <body> <select> <option style="color:red;font-weight:700;font-family:courier new;">One</option> <option>Two</option> <option>Three</option> </select> </body> </html>

  12. Hériter du DropDownList • Ajout de propriétés • Réécrire le RenderContents

  13. Customiser le SmartTag pour la nouvelle DropDownList • Créer un nouveau ControlDesign public override DesignerActionListCollection ActionLists { //Return DesignerActionListCollection() }

  14. 5 : MyDropDownList MyDropDownListControlDesign demo

More Related