Uređivanje

Dijeli putem


WebPartManager.Personalization Property

Definition

Gets a reference to an object that contains personalization data for a Web page.

public:
 property System::Web::UI::WebControls::WebParts::WebPartPersonalization ^ Personalization { System::Web::UI::WebControls::WebParts::WebPartPersonalization ^ get(); };
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)]
public System.Web.UI.WebControls.WebParts.WebPartPersonalization Personalization { get; }
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)>]
member this.Personalization : System.Web.UI.WebControls.WebParts.WebPartPersonalization
Public ReadOnly Property Personalization As WebPartPersonalization

Property Value

A WebPartPersonalization that contains personalization data.

Attributes

Examples

The following code example demonstrates how to use the Personalization property programmatically.

The following Web page allows a user to enter edit mode to edit certain aspects of the Calendar control. The Toggle Scope button switches the page to user or shared personalization scope. The Edit Mode and Browse Mode buttons each switch the page into the appropriate display mode. Notice that in the <script> tag section of the file, two of the methods that handle events use the Personalization property to access useful members of the underlying object. Specifically, these methods use the ToggleScope method and the Scope property on the object accessed through the Personalization property.

<%@ Page Language="c#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  protected void Button1_Click(object sender, EventArgs e)
  {
    if ((mgr1.Personalization.Scope == PersonalizationScope.User)
      && (mgr1.Personalization.CanEnterSharedScope))
    {
      mgr1.Personalization.ToggleScope();
    }
    else if (mgr1.Personalization.Scope ==
      PersonalizationScope.Shared)
    {
      mgr1.Personalization.ToggleScope();
    }
    else
    {
      // If the user cannot enter shared scope you may want
      // to notify them on the page.
    }
  }

  protected void Button2_Click(object sender, EventArgs e)
  {
    mgr1.DisplayMode = WebPartManager.EditDisplayMode;
  }

  protected void Button3_Click(object sender, EventArgs e)
  {
    mgr1.DisplayMode = WebPartManager.BrowseDisplayMode;
  }

  protected void Page_Load(object sender, EventArgs e)
  {
    Label1.Text = "Scope is: "
      + mgr1.Personalization.Scope.ToString();
  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <asp:WebPartManager ID="mgr1" runat="server" />
      <asp:WebPartZone ID="WebPartZone1" runat="server">
        <ZoneTemplate>
          <asp:Calendar ID="Calendar1" runat="server" />
        </ZoneTemplate>
      </asp:WebPartZone>
      <asp:EditorZone ID="EditorZone1" runat="server">
        <ZoneTemplate>
          <asp:AppearanceEditorPart ID="AppearanceEditorPart1" 
            runat="server"  />
          <asp:BehaviorEditorPart ID="BehaviorEditorPart1" 
            runat="server" />
        </ZoneTemplate>
      </asp:EditorZone>
      <hr />
      <asp:Button ID="Button1" runat="server" Text="Toggle Scope" OnClick="Button1_Click"  />
      <asp:Button ID="Button2" runat="server" Text="Edit Mode" OnClick="Button2_Click" />
      <asp:Button ID="Button3" runat="server" Text="Browse Mode" OnClick="Button3_Click" />
      <br />
      <asp:Label ID="Label1" runat="server" Text="" />
     </div>
     </form>
</body>
</html>
<%@ Page Language="vb" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  Protected Sub Button1_Click(ByVal sender As Object, _
    ByVal e As System.EventArgs)
    If mgr1.Personalization.Scope = PersonalizationScope.User _
      AndAlso mgr1.Personalization.CanEnterSharedScope Then
      mgr1.Personalization.ToggleScope()
    ElseIf mgr1.Personalization.Scope = _
      PersonalizationScope.Shared Then
      mgr1.Personalization.ToggleScope()
    Else
      ' If the user cannot enter shared scope you may want
      ' to notify them on the page.
    End If
    
  End Sub
  
  Protected Sub Button2_Click(ByVal sender As Object, _
    ByVal e As System.EventArgs)
    mgr1.DisplayMode = WebPartManager.EditDisplayMode
  End Sub
  
  Protected Sub Button3_Click(ByVal sender As Object, _
    ByVal e As System.EventArgs)
    mgr1.DisplayMode = WebPartManager.BrowseDisplayMode
  End Sub

  Protected Sub Page_Load(ByVal sender As Object, _
    ByVal e As System.EventArgs)
    Label1.Text = "Scope is: " & mgr1.Personalization.Scope.ToString()
  End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <asp:WebPartManager ID="mgr1" runat="server" />
      <asp:WebPartZone ID="WebPartZone1" runat="server">
        <ZoneTemplate>
          <asp:Calendar ID="Calendar1" runat="server" />
        </ZoneTemplate>
      </asp:WebPartZone>
      <asp:EditorZone ID="EditorZone1" runat="server">
        <ZoneTemplate>
          <asp:AppearanceEditorPart ID="AppearanceEditorPart1" 
            runat="server"  />
          <asp:BehaviorEditorPart ID="BehaviorEditorPart1" 
            runat="server" />
        </ZoneTemplate>
      </asp:EditorZone>
      <hr />
      <asp:Button ID="Button1" runat="server" Text="Toggle Scope" OnClick="Button1_Click"  />
      <asp:Button ID="Button2" runat="server" Text="Edit Mode" OnClick="Button2_Click" />
      <asp:Button ID="Button3" runat="server" Text="Browse Mode" OnClick="Button3_Click" />
      <br />
      <asp:Label ID="Label1" runat="server" Text="" />
     </div>
     </form>
</body>
</html>

For the code example to run, you also must enable a user or users to personalize pages in shared scope. Add an entry to the Web.config file, within the <system.web> section, that looks like the following markup.

<webParts>  
  <personalization>  
    <authorization>  
      <allow  
        users="[Replace the text and brackets with a user name or   
           group.]"  
        roles="admin"   
        verbs="enterSharedScope"  />  
    </authorization>  
  </personalization>  
</webParts>   

After you load the page in a browser, click the Toggle Scope button, and notice that the page now says the scope is shared. Click Edit Mode to change the display mode, click the verbs menu on the visible control, and select Edit from the menu. Notice that the user interface (UI) for both editing controls appears. Now click Browse Mode to return to normal browsing. If the page says it is in shared scope, click Toggle Scope again to ensure the page is in user scope. Next, follow the same steps to edit the control again, but notice that now in the editing UI, the BehaviorEditorPart control does not appear. That is because this control only works when the page is in shared personalization scope.

Remarks

The Personalization property provides a way to access the WebPartPersonalization object that is associated with a page through the WebPartManager control. Using this property, you can access the various members of the personalization object. For example, you can use the ToggleScope method to switch the page's personalization scope from shared to user scope, or vice versa. You can also find out the current personalization scope of the page, whether personalization is even enabled on the page, which provider is being used for the personalization data, and more.

Note that the data referenced by the Personalization property is only the page-level personalization data that is tracked by the WebPartManager control. Control-specific personalization data, such as the values of personalizable properties on WebPart controls, is not part of the Personalization property.

Note

For more information on Web Parts personalization, see Web Parts Personalization Overview.

Applies to

See also