Page view counter

Multiple Webparts on shared profile

Last post 06-04-2004 1:41 PM by mharder. 2 replies.

Sort Posts:

  • Multiple Webparts on shared profile

    05-30-2004, 4:26 PM
    • Loading...
    • dcanevet
    • Joined on 05-30-2004, 4:16 PM
    • PARIS - FRANCE
    • Posts 6
    • Points 30
    Hi,

    I have a webform having multiple WebPartZones. I designed a custom personalizable webpart that I put this webpart many times in my page. This configuration is stored in the shared profile.
    Can I be sure each instance of my custom webpart will always have the same Unique ID? (independently of other controls on my page, of other webparts in my zone, and independently of the logged-in profile!)

    Regards,
    Denis
    Denis CANEVET
  • Re: Multiple Webparts on shared profile

    05-30-2004, 7:02 PM
    • Loading...
    • Fredrik N
    • Joined on 06-22-2002, 5:03 AM
    • Sweden
    • Posts 5,333
    • Points 29,632
    • TrustedFriends-MVPs
    Basically yes, but you can't if you add a WebPart dynamically, for example, if you create a WebPart that inherits the WebPart class, the Unique ID will be changed every time for the WebPart if you add it dynamically to a Zone in your server code. But if you add the WebPart to the WebPartZone in the ASP.Net page (Source view) it will always have the same Unique ID if you don't change the WebPartManger ID or the WebParts ID in the future. If you add a server control or a user control to a WebPartZone (controils that doesn’t inherit the WebPart class), the WebPartZone control will create a GenericWebpart that will have the same UniqueID, as long as the ID of the control is the same.
    /Fredrik Normén - fredrikn @ twitter

    Microsoft MVP, MCSD, MCAD, MCT

    ASPInsiders
    My Blog
  • Re: Multiple Webparts on shared profile

    06-04-2004, 1:41 PM
    • Loading...
    • mharder
    • Joined on 11-22-2002, 7:03 AM
    • Redmond, WA
    • Posts 917
    • Points 4,537
    • Moderator
    All WebParts are parented to the WebPartManager, and all WebParts are required to have an ID.

    For a static WebPart (a WebPart in the ZoneTemplate of a WebPartZone), you must specify the ID in the persistence format, so the UniqueID of the WebPart is the ID of the WebPartManager, plus the ID of the WebPart itself.

    When you add a dynamic WebPart, we generate a random ID for the WebPart. However, this ID will stay the same as long as the WebPart is on the page. We need the ID to stay constant, since the WebPart ID is used as the key for storing Personalization data.
    http://blogs.msdn.com/mharder

    This posting is provided "AS IS" with no warranties, and confers no rights.
Page 1 of 1 (3 items)