1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / GenericContent as WebEditor in user control complex properties?

GenericContent as WebEditor in user control complex properties?

2 posts, 0 answered
  1. Michael Westafer
    Michael Westafer avatar
    4 posts
    Registered:
    28 Dec 2007
    07 Jul 2009
    Link to this post
    I've been trying to use a GenericContent as the WebEditor for the property of a user control.  It seems to work as expected. However, selecting shared content from within the complex property (WebEditor) window does not seem to work as expected.

    So, the idea is to create a [public] browsable string property in a user control, allowing the user to update the content via a GenericContent (RadEditor) dialog window.  I'm wondering if anyone has any tips for me; perhaps a better way to achieve this?

    GCTabs.ascx
    1 <%@ Control Language="C#" AutoEventWireup="true" CodeFile="GCTabs.ascx.cs" Inherits="GCTabs" %> 
    2 <asp:Literal ID="GCTab1" runat="server" /> 
    3 <asp:Literal ID="GCTab2" runat="server" /> 
    4 <asp:Literal ID="GCTab3" runat="server" /> 
    5 <asp:Literal ID="GCTab4" runat="server" /> 
    6 <asp:Literal ID="GCTab5" runat="server" /> 
    7  

    GCTabs.ascx.cs
    1 using System; 
    2 using System.Data; 
    3 using System.ComponentModel; 
    4 using System.Configuration; 
    5 using System.Collections; 
    6 using System.Web; 
    7 using System.Web.Security; 
    8 using System.Web.UI; 
    9 using System.Web.UI.WebControls; 
    10 using System.Web.UI.WebControls.WebParts; 
    11 using System.Web.UI.HtmlControls; 
    12  
    13 public partial class GCTabs : System.Web.UI.UserControl, Telerik.Cms.IContentContainer 
    14
    15     private Hashtable _Fields; 
    16     private const int MAX_TABS = 5; 
    17
    18     #region IContentContainer Members 
    19     [Browsable(false)] 
    20     public object Content 
    21     { 
    22         get 
    23         { 
    24             return false
    25         } 
    26         set 
    27         { 
    28             ; 
    29         } 
    30     } 
    31     [Browsable(false)] 
    32     public string ProviderName 
    33     { 
    34         get 
    35         { 
    36             return ""
    37         } 
    38         set 
    39         { 
    40             ; 
    41         } 
    42     } 
    43     #endregion 
    44  
    45     [Category("Generic Content 1")] 
    46     [DisplayName("Content")] 
    47     [Telerik.Cms.Web.UI.WebEditor("Telerik.Cms.Engine.WebControls.HtmlContentEditor, Telerik.Cms.Engine")] 
    48     [TypeConverter(typeof(StringConverter))] 
    49     public string GC1Content 
    50     { 
    51         get 
    52         { 
    53             return (string)((Hashtable)this._Fields["GC1"])["Content"]; 
    54         } 
    55         set 
    56         { 
    57             ((Hashtable)this._Fields["GC1"])["Content"] = value; 
    58         } 
    59     } 
    60     [Category("Generic Content 1")] 
    61     [DisplayName("Visible")] 
    62     public bool GC1IsVisible 
    63     { 
    64         get 
    65         { 
    66             return (bool)((Hashtable)this._Fields["GC1"])["Visible"]; 
    67         } 
    68         set 
    69         { 
    70             ((Hashtable)this._Fields["GC1"])["Visible"] = value; 
    71         } 
    72     } 
    73  
    74     [Category("Generic Content 2")] 
    75     [DisplayName("Content")] 
    76     [Telerik.Cms.Web.UI.WebEditor("Telerik.Cms.Engine.WebControls.HtmlContentEditor, Telerik.Cms.Engine")] 
    77     [TypeConverter(typeof(StringConverter))] 
    78     public string GC2Content 
    79     { 
    80         get 
    81         { 
    82             return (string)((Hashtable)this._Fields["GC2"])["Content"]; 
    83         } 
    84         set 
    85         { 
    86             ((Hashtable)this._Fields["GC2"])["Content"] = value; 
    87         } 
    88     } 
    89     [Category("Generic Content 2")] 
    90     [DisplayName("Visible")] 
    91     public bool GC2IsVisible 
    92     { 
    93         get 
    94         { 
    95             return (bool)((Hashtable)this._Fields["GC2"])["Visible"]; 
    96         } 
    97         set 
    98         { 
    99             ((Hashtable)this._Fields["GC2"])["Visible"] = value; 
    100         } 
    101     } 
    102  
    103     [Category("Generic Content 3")] 
    104     [DisplayName("Content")] 
    105     [Telerik.Cms.Web.UI.WebEditor("Telerik.Cms.Engine.WebControls.HtmlContentEditor, Telerik.Cms.Engine")] 
    106     [TypeConverter(typeof(StringConverter))] 
    107     public string GC3Content 
    108     { 
    109         get 
    110         { 
    111             return (string)((Hashtable)this._Fields["GC3"])["Content"]; 
    112         } 
    113         set 
    114         { 
    115             ((Hashtable)this._Fields["GC3"])["Content"] = value; 
    116         } 
    117     } 
    118     [Category("Generic Content 3")] 
    119     [DisplayName("Visible")] 
    120     public bool GC3IsVisible 
    121     { 
    122         get 
    123         { 
    124             return (bool)((Hashtable)this._Fields["GC3"])["Visible"]; 
    125         } 
    126         set 
    127         { 
    128             ((Hashtable)this._Fields["GC3"])["Visible"] = value; 
    129         } 
    130     } 
    131  
    132     [Category("Generic Content 4")] 
    133     [DisplayName("Content")] 
    134     [Telerik.Cms.Web.UI.WebEditor("Telerik.Cms.Engine.WebControls.HtmlContentEditor, Telerik.Cms.Engine")] 
    135     [TypeConverter(typeof(StringConverter))] 
    136     public string GC4Content 
    137     { 
    138         get 
    139         { 
    140             return (string)((Hashtable)this._Fields["GC4"])["Content"]; 
    141         } 
    142         set 
    143         { 
    144             ((Hashtable)this._Fields["GC4"])["Content"] = value; 
    145         } 
    146     } 
    147     [Category("Generic Content 4")] 
    148     [DisplayName("Visible")] 
    149     public bool GC4IsVisible 
    150     { 
    151         get 
    152         { 
    153             return (bool)((Hashtable)this._Fields["GC4"])["Visible"]; 
    154         } 
    155         set 
    156         { 
    157             ((Hashtable)this._Fields["GC4"])["Visible"] = value; 
    158         } 
    159     } 
    160  
    161     [Category("Generic Content 5")] 
    162     [DisplayName("Content")] 
    163     [Telerik.Cms.Web.UI.WebEditor("Telerik.Cms.Engine.WebControls.HtmlContentEditor, Telerik.Cms.Engine")] 
    164     [TypeConverter(typeof(StringConverter))] 
    165     public string GC5Content 
    166     { 
    167         get 
    168         { 
    169             return (string)((Hashtable)this._Fields["GC5"])["Content"]; 
    170         } 
    171         set 
    172         { 
    173             ((Hashtable)this._Fields["GC5"])["Content"] = value; 
    174         } 
    175     } 
    176     [Category("Generic Content 5")] 
    177     [DisplayName("Visible")] 
    178     public bool GC5IsVisible 
    179     { 
    180         get 
    181         { 
    182             return (bool)((Hashtable)this._Fields["GC5"])["Visible"]; 
    183         } 
    184         set 
    185         { 
    186             ((Hashtable)this._Fields["GC5"])["Visible"] = value; 
    187         } 
    188     } 
    189  
    190     public GCTabs() : base() 
    191     { 
    192         this.InitializeGCTabs(); 
    193     } 
    194  
    195     protected void InitializeGCTabs() 
    196     { 
    197         if (this._Fields == null
    198         { 
    199             this._Fields = new Hashtable(); 
    200             for (int i = 1; i <= GCTabs.MAX_TABS; i++) 
    201             { 
    202                 string field = "GC" + i.ToString(); 
    203                 this._Fields.Add(field, new Hashtable()); 
    204                 ((Hashtable)this._Fields[field]).Add("Content"""); 
    205                 ((Hashtable)this._Fields[field]).Add("Visible"false); 
    206             } 
    207         } 
    208     } 
    209  
    210     protected void Page_Init(object sender, EventArgs e) 
    211     { 
    212         this.GCTab1.Visible = this.GC1IsVisible; 
    213         if (this.GC1IsVisible) 
    214         { 
    215             this.GCTab1.Text = this.GC1Content; 
    216         } 
    217  
    218         this.GCTab2.Visible = this.GC2IsVisible; 
    219         if (this.GC2IsVisible) 
    220         { 
    221             this.GCTab2.Text = this.GC2Content; 
    222         } 
    223  
    224         this.GCTab3.Visible = this.GC3IsVisible; 
    225         if (this.GC3IsVisible) 
    226         { 
    227             this.GCTab3.Text = this.GC3Content; 
    228         } 
    229  
    230         this.GCTab4.Visible = this.GC4IsVisible; 
    231         if (this.GC4IsVisible) 
    232         { 
    233             this.GCTab4.Text = this.GC4Content; 
    234         } 
    235  
    236         this.GCTab5.Visible = this.GC5IsVisible; 
    237         if (this.GC5IsVisible) 
    238         { 
    239             this.GCTab5.Text = this.GC5Content; 
    240         } 
    241     } 
    242
    243  
    244  
    245  



  2. Dido
    Dido avatar
    149 posts
    Registered:
    24 Sep 2012
    13 Jul 2009
    Link to this post
    Hi michael westafer,

    Just a look through code, but I believe I know where your problem is.

    You are using IContentContainer , while you should use IGenericContent. There is a good example of its usage in the offline help, more precisely - "How-to > Controls > Built-in Controls > Wrap Generic Content Control in a User Control".

    Please don't hesitate to ask if you have more questions or some feedback.

    All the best,
    Dido
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
2 posts, 0 answered