Problem with EditableDesignerRegion and Set/Get methods ..

Discussion in 'ASP .Net Building Controls' started by Micke Andersson, Jul 31, 2006.

  1. I have a slight problem with
    SetEditableDesignerRegionContent(region,content) .. it keeps telling me that
    I already have a control with the same ID when I try to update, thus failing
    and somehow actually adding stuff twice ..

    so what am I doing wrong? I have a custom control which contains a list of
    other controls (TabControl and a list of Tabs), but I cannot use templates
    since I want attributes on the Tabs themselves). It all works runtime - and
    in the designer - but on and off when I do certain changes, I cannot persist
    the EditableDesignerRegion contents due to contents apparently appearing
    twice.

    The designer is actually bound to the TabControl, but actually what I am
    editing is the contents of the Tab - the TabControl selects what Tab is
    active dynamically so I don't really know how to do it another way. I'm
    pretty certain the problem is at or near the GetEditable...() and
    SetEditable...() functions, so can anyone give me a hint on how to persist
    Tab data from the designer correctly?

    I tried looking at information about ControlParser and ControlPersister, but
    there's not a lot out there that i can can find :(

    EditableDesignerRegion is created from a <div> tag surrounding each tab
    (generated by TabControl.Render()) and is filled with the designer mark
    (__designer="0" in this case) when in design mode.

    /Micke Andersson


    public override string
    GetEditableDesignerRegionContent(EditableDesignerRegion region) {
    IDesignerHost host =
    (IDesignerHost)Component.Site.GetService(typeof(IDesignerHost));
    try {
    if (host != null) {
    Tab tab = _c.Tabs[region.Name];
    string s = "";
    foreach (Control cc in tab.Controls) {
    s += ControlPersister.PersistControl(cc, host);
    }
    return s;
    }
    } catch (Exception ex) {
    _(" EXCEPTION: " + ex.Message);
    }
    return "";
    }

    public override void SetEditableDesignerRegionContent(EditableDesignerRegion
    region, string content) {
    int currentstep = 0;
    if (content == null)
    return;
    try {
    IDesignerHost host =
    (IDesignerHost)Component.Site.GetService(typeof(IDesignerHost));
    if (host != null) {
    Tab tab = _c.Tabs[region.Name];
    tab.Controls.Clear();
    Control[] c = ControlParser.ParseControls(host, content);
    foreach (Control cc in c) {
    tab.Controls.Add(cc);
    }
    }
    } catch (Exception ex) {
    _(" EXCEPTION: " + ex.Message);
    }
    }
     
    Micke Andersson, Jul 31, 2006
    #1
    1. Advertising

  2. Noone? :(

    "Micke Andersson" wrote:

    > I have a slight problem with
    > SetEditableDesignerRegionContent(region,content) .. it keeps telling me that
    > I already have a control with the same ID when I try to update, thus failing
    > and somehow actually adding stuff twice ..
     
    Micke Andersson, Aug 2, 2006
    #2
    1. Advertising

  3. hi Micke, I dont know the structure of your code logic and what you are
    doing exactly to get this problem. One of the things i have noticed when
    using designer regions and editabledesignerregions is that if i emit the
    call to base.SetViewFlags in the Initialize method of my designer class then
    unique ids are not maintained.


    /*
    * The designer host calls Initialize to initialize the component
    for design.
    * The base implementation will throw an exception if the associated
    * control does not implement the INamingContainer interface.
    */
    public override void Initialize(IComponent component)
    {
    this._c = (Tab)component;
    base.Initialize(component);
    // Seems like without setting ViewFalgs for TemplateEditing then
    // any control you add into the region does not maintain
    // a unique id :| No idea why this is the case but it dont
    bother me
    // to add this simple one line.
    base.SetViewFlags(ViewFlags.TemplateEditing, true);
    }

    if this did not fix your issue, then let me know and i'll try to put
    together a small test control with tabs and designer regions /
    editabledesignerregions working, to get you started.

    Regards,
    Alessandro Zifiglio
    http://www.AsyncUI.net

    "Micke Andersson" <> ha scritto nel
    messaggio news:...
    > Noone? :(
    >
    > "Micke Andersson" wrote:
    >
    >> I have a slight problem with
    >> SetEditableDesignerRegionContent(region,content) .. it keeps telling me
    >> that
    >> I already have a control with the same ID when I try to update, thus
    >> failing
    >> and somehow actually adding stuff twice ..

    >
     
    Alessandro Zifiglio, Aug 2, 2006
    #3
  4. That actually appears to have fixed it. While I am not editing templates per
    se, I understand the logic behind it, kinda. Maybe they should have called
    that option something else - something more generic- if it just makes the
    designer aware of the fact that there's actually other web code living around
    it.

    Oh, and write some help past the automatically generated stuff once you get
    past looking for help about adding an onClick event :)

    Thanks a lot for helping out,
    /Micke

    "Alessandro Zifiglio" wrote:

    > hi Micke, I dont know the structure of your code logic and what you are
    > doing exactly to get this problem. One of the things i have noticed when
    > using designer regions and editabledesignerregions is that if i emit the
    > call to base.SetViewFlags in the Initialize method of my designer class then
    > unique ids are not maintained.
     
    Micke Andersson, Aug 2, 2006
    #4
  5. Your welcome, Micke. I agree that SetViewFlags is badly documented and named
    =P

    Regards,
    Alessandro Zifiglio
    http://www.AsyncUI.net

    "Micke Andersson" <> ha scritto nel
    messaggio news:...
    > That actually appears to have fixed it. While I am not editing templates
    > per
    > se, I understand the logic behind it, kinda. Maybe they should have called
    > that option something else - something more generic- if it just makes the
    > designer aware of the fact that there's actually other web code living
    > around
    > it.
    >
    > Oh, and write some help past the automatically generated stuff once you
    > get
    > past looking for help about adding an onClick event :)
    >
    > Thanks a lot for helping out,
    > /Micke
    >
    > "Alessandro Zifiglio" wrote:
    >
    >> hi Micke, I dont know the structure of your code logic and what you are
    >> doing exactly to get this problem. One of the things i have noticed when
    >> using designer regions and editabledesignerregions is that if i emit the
    >> call to base.SetViewFlags in the Initialize method of my designer class
    >> then
    >> unique ids are not maintained.

    >
     
    Alessandro Zifiglio, Aug 3, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ajay Singh Tomar

    Invoking of set/get methods in JIBX

    Ajay Singh Tomar, Jan 22, 2004, in forum: Java
    Replies:
    0
    Views:
    559
    Ajay Singh Tomar
    Jan 22, 2004
  2. Generic Usenet Account

    Naming convention for accessor methods (get/set)

    Generic Usenet Account, Sep 19, 2003, in forum: C++
    Replies:
    24
    Views:
    2,896
    Glen Low
    Oct 6, 2003
  3. Replies:
    4
    Views:
    390
  4. Christophe Peillet

    Adding controls to EditableDesignerRegion/ITemplate in code.

    Christophe Peillet, Apr 4, 2006, in forum: ASP .Net Building Controls
    Replies:
    7
    Views:
    204
    Alessandro Zifiglio
    Apr 10, 2006
  5. Kenneth McDonald
    Replies:
    5
    Views:
    378
    Kenneth McDonald
    Sep 26, 2008
Loading...

Share This Page