1 out of 2 rated this helpful Rate this topic

WebPartPersonalization.ToggleScope Method

Switches the current page's personalization scope from User to Shared or from Shared to User.

Namespace:  System.Web.UI.WebControls.WebParts
Assembly:  System.Web (in System.Web.dll)
public virtual void ToggleScope()
Exception Condition
InvalidOperationException

The current user does not have the user capability to enter Shared scope when attempting to switch from User scope to Shared scope.

- or -

The WebPartPersonalization instance has not completed initialization.

- or -

The Page instance for the associated WebPartManager is Nothing.

- or -

The value of the Request property on the WebPartManager control's associated Page instance is Nothing.

ArgumentOutOfRangeException

An attempt was made to toggle to a scope that is not defined in the PersonalizationScope enumeration. Technically, this situation should never occur.

This method toggles the currently executing page's personalization scope. Toggling the scope results in a Transfer back to the current executing page.

This method performs no operation if it is called while an export or import of a Web Parts control is occurring.

If a toggle scope request occurs for a page that was submitted via a POST request, then any query string values will be preserved during the transfer; query string parameters are not preserved if the page was submitted via a GET request.

The following code demonstrates using the ToggleScope method. This code is part of a larger code sample found in the WebPartPersonalization class description.

// Allows authorized user to change personalization scope.
protected void Toggle_Scope_Button_Click(object sender, EventArgs e)
{
    if (_manager.Personalization.CanEnterSharedScope)
    {
        _manager.Personalization.ToggleScope();
    }

}


Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
POSTed values lost, QUERY STRING values retained

The documentation states the opposite of what actually happens. It appears that ToggleScope() does the equivalent of calling

Server.Transfer(Request.RawUrl,false);

This action throws away the POSTed data, but will preserve QueryString parameters. (More precisely, it will recreate them because they are part of the RawUrl.) If ToggleScope() called

Server.Transfer(Request.RawUrl,true);

instead, then POSTed data would be preserved. Note that posted data includes state changes for things like dropdown lists, so invoking ToggleScope() will cause state changes to be lost, as well as events associated with state changes (e.g., SelectedIndexChanged event).

If I have this wrong please let me know!

[tdykstra]ToggleScope() does call Server.Transfer(url,false), but it does not use Request.RawUrl for the url. It strips or includes the query string values according to the criteria outlined in the documentation.