Prevent adding the same web part twice from a catalog

Last post 03-17-2008 12:04 PM by matthewwebster. 10 replies.

Sort Posts:

  • Prevent adding the same web part twice from a catalog

    12-13-2005, 4:34 PM
    I have a catalogzone with a declarativecatalogpart inside.  Right now if you select a web part from the catalog and add it, it stays on the list, and you can add it again.  How do I take a web part off the list after it has been added?  Is there not just an attribute to prevent someone from having multiple of the same web part at once?
  • Re: Prevent adding the same web part twice from a catalog

    12-16-2005, 2:23 PM
    • Contributor
      4,557 point Contributor
    • mharder
    • Member since 11-22-2002, 12:03 PM
    • Redmond, WA
    • Posts 917
    • AspNetTeam
      Moderator

    The DeclarativeCatalogPart is specifically designed to allow adding multiple instances of a WebPart type.  Why do you want to disallow this scenario?

    At any rate, the PageCatalogPart sounds like it might do the trick for you.  The PageCatalogPart lists all the closed WebParts on the page.  So instead of adding your WebParts to the DeclarativeCatalogPart, you would add them to the page instead, but as closed WebParts.  Then, they would appear in the PageCatalogPart, but could only be "added" to the page once.

    -Mike

    http://blogs.msdn.com/mharder

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: Prevent adding the same web part twice from a catalog

    12-16-2005, 8:30 PM
    So many types of web parts, I didn't realize I was just using the wrong one.  Thanks, this really helped me a lot.

    Hey could you also tell me what ChromeType is for?  "TitleOnly", "BorderOnly", I don't see how these would ever be useful.  ChromeState's purpose I understand, but not this ChromeType and ChromeStyle.
  • Re: Prevent adding the same web part twice from a catalog

    12-19-2005, 8:28 PM
    • Contributor
      4,557 point Contributor
    • mharder
    • Member since 11-22-2002, 12:03 PM
    • Redmond, WA
    • Posts 917
    • AspNetTeam
      Moderator

    ChromeStyle is the style (background color, border, etc.) applied to the chrome rendered around the part.

    ChromeType controls what part of the chrome you want rendered.  For example, say you didn't want to render the title bar on the WebParts.

    -Mike

    http://blogs.msdn.com/mharder

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: Prevent adding the same web part twice from a catalog

    12-28-2006, 11:06 AM
    • Member
      94 point Member
    • davidanderson
    • Member since 08-29-2006, 8:59 PM
    • Nashville TN
    • Posts 91
    Dumb question: How do you add a part as "closed?" All I see is a visibility property. I'd like to add several parts that are already closed when the page initially displays.
  • Re: Prevent adding the same web part twice from a catalog

    02-22-2007, 5:10 PM
    • Member
      2 point Member
    • RaphaelThiney
    • Member since 01-19-2007, 2:38 PM
    • Posts 2
    How do you add a part as "closed?"
  • Re: Prevent adding the same web part twice from a catalog

    03-28-2007, 8:05 AM
    • Member
      248 point Member
    • rmr.adduri
    • Member since 12-21-2005, 12:01 PM
    • Hyderabad
    • Posts 62

    Hi,

    Can you please tell me how to load these web user controls dynamically to declarativewebpart catalog instead of registering under the declarativecatalogpart. i have a requirement like this. please help me.

    Regards,
    Ram Mohan Rao Adduri,
    Techinical Associate,
    Prokarma
    Hyderabad.
    Mobile: 9490118545
  • Re: Prevent adding the same web part twice from a catalog

    03-30-2007, 4:13 AM
    • Contributor
      4,557 point Contributor
    • mharder
    • Member since 11-22-2002, 12:03 PM
    • Redmond, WA
    • Posts 917
    • AspNetTeam
      Moderator

    If you want to load the WebParts dynamically, you should write a custom CatalogPart.  DeclarativeCatalogPart is only intended for the declarative scenario.

    -Mike

    http://blogs.msdn.com/mharder

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: Prevent adding the same web part twice from a catalog

    03-30-2007, 5:39 AM
    • Member
      248 point Member
    • rmr.adduri
    • Member since 12-21-2005, 12:01 PM
    • Hyderabad
    • Posts 62

    Thanks for your reply. can you please provide me the source code regarding this if your have.

    Thanks,

     Ram

    Regards,
    Ram Mohan Rao Adduri,
    Techinical Associate,
    Prokarma
    Hyderabad.
    Mobile: 9490118545
  • Re: Prevent adding the same web part twice from a catalog

    04-26-2007, 8:50 AM
    • Member
      5 point Member
    • kuldeepsaini80
    • Member since 04-09-2007, 12:56 PM
    • India
    • Posts 8

    there is event of webpartmanager ( WebPartManager1_WebPartAdding) this event invokd before webpart adding to webpartmanager.

    You can  write your code in this event.to prevent adding duplicate webpart by checking whetjer there is web part in webparzone or not

     

  • Re: Prevent adding the same web part twice from a catalog

    03-17-2008, 12:04 PM
    • Participant
      1,260 point Participant
    • matthewwebster
    • Member since 09-18-2003, 3:56 PM
    • London
    • Posts 324

    Thankyou for this!  I was wondering just exactly this thread's original question :)   Aren't forums great!

    I was wondering how many different ways people have performed filtering of controls to force only one instance of a web part?

    The way I did it was to compare the class name of the control within the added web parts against the one being added...

     
    protected void WebPartManager1_WebPartAdding(object sender, WebPartAddingEventArgs e)
    {
        // get element being added - used a base class to check each control can/not be added multiple times
        MyControl addElement = (MyControl)((GenericWebPart)e.WebPart).ChildControl;
    
        // if the control is allowed multiple times (ie: not a 'singletonpart') exit check
        if (!addElement.isSingletonPart)
            return;
    
        // get the new element's control pathname
        string path = addElement.GetType().Name;
    
        // check pathname against each element currently in the document
        foreach (GenericWebPart part in WebPartManager1.WebParts)
        {
            if (part.ChildControl.GetType().Name.Equals(path))
            {
                // found that the web part control has already been added, tell user and bail out of loop
                singletonWebPartWarning.Visible = true;
                e.Cancel = true;
                break;
            }
        }
    }
    
     
    This post with no guarantees associated, being a personal submittal with no affiliation intended or implied.
    <mc:WittyRemark runat="server" id="wr1" />
Page 1 of 1 (11 items)