1. Certified Abuser
    ASP Good Citizen (1000 - 1499 posts)

    Join Date
    Jan 2005
    Line 73 ---^
    Rep Power

    Set Shared State View For Web Parts ie.. Moderator

    Hello all,

    Ive got a tool im working on that will use a set of user controls like a template I want to have a moderator that can change template order and add new items then another set of users will be able to change the order and appearance of the page and then set the userState of a mock account so the moderator can view and apply if necessary.

    My main situation is that im trying to figure out how to set the shared state of a page after its been put live i can see how to reset individual user states but i cant seem to find a setShared state method i was reading of a stored proc when using SQL as your provider but im unsure if this is what im going to have to call or if there is a nice and easy method already out there

    Ive got this sample code from ASP.NET "how do I" video series to work with as my test page. Does anyone know of an easy way to accomplish this?

        Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
            Select Case DropDownList1.SelectedValue
                Case "Browse"
                    WebPartManager1.DisplayMode = WebPartManager.BrowseDisplayMode
                Case "Design"
                    WebPartManager1.DisplayMode = WebPartManager.DesignDisplayMode
                Case "Catalog"
                    WebPartManager1.DisplayMode = WebPartManager.CatalogDisplayMode
                Case "Edit"
                    WebPartManager1.DisplayMode = WebPartManager.EditDisplayMode
                Case Else
            End Select
        End Sub
        Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        End Sub
    Thanks in advance
    werD, MCSD .Net
    <% ASP,.NET App Development %>

    Really Help People with Real Diseases... And Get a Cool Blue Flower!

    If a post has helped you please use the scales... we all need bigger heads
  2. #2
  3. Unholy Moderator
    ASP Mastermind (5000+ posts)

    Join Date
    Oct 2003
    In hell, where did you think?
    Rep Power
    For Specific Users
    WebPartManager1.Personalization.Scope = PersonalizationScope.User
    Shared By All Users
    WebPartManager1.Personalization.Scope = PersonalizationScope.Shared
    Originally Posted by MSDN
    Shared: When referring to the scope on the WebPartManagercontrol, Shared scope means that personalization data applies to all users for all personalizable controls on a page and is also available to be saved on the page.
    When referring to the scope associated with a Web Parts control property, Shared scope indicates that the property normally only allows loading or saving of data associated with all users.

    User: When referring to the scope on the WebPartManagercontrol, User scope means that personalization data that is user-specific, as well as personalization data that applies to all users, is loaded for all personalizable controls on a page. Only personalization data that is user-specific can be saved on the page.
    When referring to the scope associated with a Web Parts control property, User scope indicates that the property can only load and store data applicable to all users when running on a page in Shared scope. However, when the property's control is running on a page in User scope, the property's per-user and all-user data will be loaded and merged. In this case, though, only per-user data will be saved when a page is running in User scope.

    Comments on this post

    • werD agrees : Thanks
  4. #3
  5. Certified Abuser
    ASP Good Citizen (1000 - 1499 posts)

    Join Date
    Jan 2005
    Line 73 ---^
    Rep Power
    Thanks memnoch,
    I couldnt figure out how to get that to work and after a little thought and a pretty good error message i figured out that its for use in conditional statements to verify the current state of the webpart manager
    after some reading
    Ive adjusted my web.config file to allow personalization
            <personalization defaultProvider="AspNetSqlPersonalizationProvider">
                <allow users="admin" verbs="enterSharedScope, modifyState"/>
                <allow roles="powerusers" verbs="enterSharedScope, modifyState"/>
    and used a nifty user control i found using context sensitive help in vs that will tell you the current scope and allow you to change the scope of the current page inorder to make changes to shared state of page
    <%@ control language="VB" %>
    <script runat="server">
      ' Use a field to reference the current WebPartManager.
    Private _manager As WebPartManager
        Private _text As String
        <Personalizable(PersonalizationScope.Shared)> _
    Public Property Title() As String
                Return _text
            End Get
            Set(ByVal value As String)
                _text = value
                Label3.Text = value
            End Set
        End Property
    Protected Sub Page_Load(ByVal src As Object, ByVal e As EventArgs) 
        ' Get the current Web Parts manager.
        _manager = WebPartManager.GetCurrentWebPartManager(Page)
        ' All radio buttons are disabled; the button settings show what the current state is.
        EnterSharedRadioButton.Enabled = False
        ModifyStateRadioButton.Enabled = False
        ' If Web Parts manager is in User scope, set scope button.
        If _manager.Personalization.Scope = PersonalizationScope.User Then
            UserScopeRadioButton.Checked = True
            SharedScopeRadioButton.Checked = True
        End If 
        ' Based on current user rights to enter Shared scope, set buttons.
        If _manager.Personalization.CanEnterSharedScope Then
            EnterSharedRadioButton.Checked = True
            No_Shared_Scope_Label.Visible = False
            Toggle_Scope_Button.Enabled = True
            EnterSharedRadioButton.Checked = False
            No_Shared_Scope_Label.Visible = True
            Toggle_Scope_Button.Enabled = False
        End If
        ' Based on current user rights to modify personalization state, set buttons.
        If _manager.Personalization.IsModifiable Then
            ModifyStateRadioButton.Checked = True
            Reset_User_Button.Enabled = True
            ModifyStateRadioButton.Checked = False
            Reset_User_Button.Enabled = False
        End If
    End Sub 'Page_Load
    ' Resets all of a user and shared personalization data for the page.
    Protected Sub Reset_CurrentState_Button_Click(ByVal src As Object, ByVal e As EventArgs) 
        ' User must be authorized to modify state before a reset can occur.
        'When in user scope, all users by default can change their own data.
        If _manager.Personalization.IsModifiable Then
        End If
    End Sub 'Reset_CurrentState_Button_Click
    ' Allows authorized user to change personalization scope.
    Protected Sub Toggle_Scope_Button_Click(ByVal sender As Object, ByVal e As EventArgs) 
        If _manager.Personalization.CanEnterSharedScope Then
        End If
    End Sub 'Toggle_Scope_Button_Click 
        &nbsp;<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
        <asp:Panel ID="Panel1" runat="server" 
        Font-Names="Verdana, Arial, Sans Serif" Height="214px" >
        <asp:Label ID="Label1" runat="server" 
          Text="Page Scope" 
          Width="120px" />&nbsp;<br />
          <asp:RadioButton ID="UserScopeRadioButton" runat="server" 
             Enabled=false />
          <asp:RadioButton ID="SharedScopeRadioButton" runat="server" 
            Enabled=false />
            <br />
            <asp:Label BorderStyle="None" Font-Bold="True" Font-Names="Courier New" ID="No_Shared_Scope_Label" Font-Size=Smaller ForeColor=red
               runat="server" Visible=false Width="179px">User cannot enter Shared scope</asp:Label>
            <br />
            <asp:Label ID="Label2" runat="server" 
          Text="Current User Can:" 
          Width="165px" />
          <br />
            <asp:RadioButton ID="ModifyStateRadioButton" runat="server" 
            Text="Modify State" Width="138px" />
            <br />
            <asp:RadioButton ID="EnterSharedRadioButton" runat="server" 
            Text="Enter Shared Scope" 
            AutoPostBack="true"  />&nbsp;<br />
            <br />
            <asp:Button ID="Toggle_Scope_Button" OnClick="Toggle_Scope_Button_Click" runat="server"
                Text="Change Scope" Width="186px" /><br />
            <br />
            <asp:Button ID="Reset_User_Button" OnClick="Reset_CurrentState_Button_Click" runat="server"
                Text="Reset Current Personalization" Width="185px" /></asp:Panel>
        &nbsp; &nbsp;
    thanks again that put me in just the direction i needed
    Last edited by werD; July 7th, 2006 at 11:25 PM.

Similar Threads

  1. Replies: 3
    Last Post: November 15th, 2005, 03:50 PM
  2. View State Corrupted or Invalid Error
    By master_key in forum .NET Development
    Replies: 0
    Last Post: January 15th, 2005, 05:45 AM
  3. Replies: 13
    Last Post: December 16th, 2004, 02:27 AM
  4. Replies: 0
    Last Post: October 31st, 2004, 02:15 AM
  5. View state across domains
    By grichards in forum .NET Development
    Replies: 0
    Last Post: February 16th, 2003, 10:43 PM

IMN logo majestic logo threadwatch logo seochat tools logo