Simple way to copy web part personalization info from one page to another.

There may be a more elegant solution, but I’ve found that I can slightly extend the SqlPersonalizationProvider class provided by Fredrik Normen (see: http://fredrik.nsquared2.com/viewpost.aspx?PostID=266)  to effectively copy personalization information from one page to another. 

 

My need was fairly specific, and the code below reflects that. However, I’m sure the concept can be generalized and applied to other situations.  Note, for example, that the solution given here applies specifically to “user” scoped personalization.

 

In my case, I have a single template page that starts out empty of parts, and this is loaded programmatically with content-specific parts by a user selecting items from a treeview.  When the user has filled the page with content as desired, they can click on a “copy” function that saves the contents of the template to another target page (which they can name and navigate to later).  This target page is actually a single aspx,  but personalized on the raw url as shown by Fredrik.  I give the page a unique url using a guid, as in “target.aspx?p=<guid>”.

 

The web-part zones in both the source and target pages need to utilize the same names.  You can use a masterpage for this, but it’s not strictly necessary.

 

The key aspect is that the personalization Blob for the template page is kept in Session state at all times, via SavePersonalizationBlob(). 

 

When the “Copy” function is executed, it triggers the copy as follows:

 

protected void btnCopy_Click(object sender, EventArgs e)

{

string newPageUrl = “~\NewPage.aspx?id=” + Guid.NewGuid().ToString();

 

newPageUrl = newPageUrl.Replace("~", Request.ApplicationPath);

      

      Session[newPageUrl] = "CopyTemplateView";

 

      Response.Redirect(newPageUrl);

}

 

Doing the redirect ensures the copy is performed immediately (and incidentally gives the user nice feedback that the copy worked!)

 

Enjoy…

/*

 * Author: Fredrik Normén - NSQUARED2

 * Copyright: 2004

 *

 * blog: http://fredrik.nsquared2.com

 * mail: fnormen@hotmail.com

 *

 * Extended by DouglasG for template copying

 *

 * DON'T REMOVE THIS COMMENT

 *

*/

using System;

using System.Data;

using System.Configuration;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

 

 

public class SqlPersonalizationProvider : System.Web.UI.WebControls.WebParts.SqlPersonalizationProvider

    {

        private string GetPath

        {

            get

            {

                HttpContext context = HttpContext.Current;

 

                if (context == null)

                    throw new HttpException("Context can not be Null");

 

                HttpRequest request = context.Request;

                if (request == null)

                    throw new HttpException("The current Context's Request property can not be Null");

 

                return request.RawUrl;

            }

        }

 

 

        protected override void LoadPersonalizationBlobs(WebPartManager webPartManager, string path, string userName, ref byte[] sharedDataBlob, ref byte[] userDataBlob)

        {

            string templatePath = HttpContext.Current.Request.ApplicationPath + "/TemplateView.aspx";

 

            if (HttpContext.Current.Session[this.GetPath] != null && HttpContext.Current.Session[this.GetPath].ToString() == "CopyTemplateView")

            {

                Byte[] dataBlob = (Byte[])HttpContext.Current.Session[templatePath];

                base.SavePersonalizationBlob(webPartManager, this.GetPath, userName, dataBlob);

                HttpContext.Current.Session.Remove(this.GetPath);

            }

 

            base.LoadPersonalizationBlobs(webPartManager, this.GetPath, userName, ref sharedDataBlob, ref userDataBlob);

 

            if (this.GetPath == templatePath)

            {

                HttpContext.Current.Session[this.GetPath] = userDataBlob;

            }

        }

 

 

        protected override void ResetPersonalizationBlob(WebPartManager webPartManager, string path, string userName)

        {

            base.ResetPersonalizationBlob(webPartManager, this.GetPath, userName);

        }

 

 

        protected override void SavePersonalizationBlob(WebPartManager webPartManager, string path, string userName, byte[] dataBlob)

        {

            base.SavePersonalizationBlob(webPartManager, this.GetPath, userName, dataBlob);

 

            string templatePath = HttpContext.Current.Request.ApplicationPath + "/TemplateView.aspx";

 

            if (this.GetPath == templatePath)

            {

                HttpContext.Current.Session[this.GetPath] = dataBlob;

            }

        }

 

 

        public override int GetCountOfState(PersonalizationScope scope, PersonalizationStateQuery query)

        {

            if ((HttpContext.Current != null) && (HttpContext.Current.Handler is Page))

            {

                Page page = (Page)HttpContext.Current.Handler;

                WebPartManager webPartManager = WebPartManager.GetCurrentWebPartManager(page);

                if (webPartManager != null)

                {

                    query.PathToMatch = this.GetPath;

                    return base.GetCountOfState(scope, query);

                }

            }

 

            return base.GetCountOfState(scope, query);

        }

    }

 

0
DouglasG
6/6/2005 11:35:32 PM
asp.net.personalization 3779 articles. 0 followers. Follow

0 Replies
644 Views

Similar Articles

[PageSpeed] 34

Reply:

Similar Artilces:

Is it possible to embed part of one web page into another web page?
Any answers will be highly appreciated.  Thanks. If you can adjust the page you want to embed onto the other page, you could use a .ascx (web forms control).  Then you can add controls to it and just drag and drop it using VS.NET from the Solution Explorer window to the webform.  You can then also embed it onto other pages in that same web project easily by drag n drop.  I hope this helps, it's not exactly a portion of a web page but may be an acceptable alternative for you.Rachel AppelMVP - ASPInsider In order to better answer this, I could use some details as ...

how to embed part of one page into another web page?
Any feedback will be highly appreciated.Thanks There is a HTML element called IFrame where you specify the size of the frame and the source URL which will then render that URL inside the IFrame. Philip Beadle (MVP, MCAD, MCT DotNetNuke Core Team) Use IFrame will contain the whole web page, right? How about I want to contain part of the web page? Thank you very much for your reply.  ...

how to navigate the url page in one web application page to another web application page
In my project one solution have 2 web apllications in one folder.like 1.webapplication1 2.webapplication2. in firt webapplication1 i created one aspx page like sample.axpx. in second webapplication2 i created one aspx page like sample2.aspx... in sample2.aspx page have hyperlinl. I need to navigate this hyperlink when i click it go to the sample.axpx. how can i write navigate url for this...help me. ..thanks  As i understand u, you need Multi Project soltuionsee this link, http://community.rainbowportal.net/blogs/jonathans_rainbow_blog/archive/2006/02/19...

Web part Personalization and Web part custom designing
  Hi all          1. I m using a GridView control in my Web Part. In that GridView i control the columns to be displayed by generating queries in run time. In my page i have six GridView controls in six web parts. Each user can customize their GridView columns. My actual requirement is i want to get the each individual user customized details when they logged in again.How can I done this plz give me a suggestion by code.    2. I want to display my web part have a rounded corner title. how can I done this. I a...

How to open another web page from one web page
Hi, I am writing an asp.net(C#) 2.0 web page with a link to another web page by clicking a button control on the page, so how can I link it in the codes? I cannot access another aspx page class within the current aspx page class.  Thanks If you need to re-direct the user to another page after pressing your Button, then use the Response.Write method like so: Response.Redirect("~/Default.aspx")Thanks, EdMicrosoft MVP - ASP/ASP.NET 1) Response.Redirect( "Destination PageName");2) Response.Transfer("Destination PageName");3) Hyperlink(  set Url="...

List web parts and web part zones from another page
Hi I'm working on an administration page that clones the content of a page within our cms. Thats the easy bit. The difficult bit is I want to be able to clone the webparts, their locations and their content that are on said page. I've been looking at the SqlPersonalizationProvider but dont think i can solve my problem by calling anything within that. I've also been looking at the webpartmanager and there does not seem to be a way of calling the methods within this class to get the content of a different page. Does anyone have any ideas how i would get the web part inform...

How to databind control in one web page from another web page
Hi all,  I have a listbox control and a button control in a web page. Once the user clicks the button another web page is opened. The new web page will accept some data from the user which will be used to databind the listbox in the first web page. In other words, the two web pages ( the parent window and the child window) are open at the same time. The child page needs to databind a control in the parent page. Is there a way to do it? I need some code. Thx in advance Update: I hate to do this. Looks like I will have to take help of viewstate and session si...

How To disable Web Parts personalization for a page?
How To disable Web Parts personalization for a page? http://msdn.microsoft.com/en-us/library/ms178182.aspxBest RegardsFalak MahmoodDon't forget to click "Mark as Answer" on the post that helped you.This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped. gunit99:How To disable Web Parts personalization for a page? Just set the attribute Personalization-Enabled to FALSE in the WebPartManager like below<asp:WebPartManager runat="server" id="WebPartManager1" personalization-enabled="fal...

Custom Personalization
Hello all, We want to provide the user a tree control containing all web parts available in the web site (available from multitple pages with different web parts on each of them) so he would be able to add them to a new web parts page. For that to happen, we are trying to use custom personalization, so we would be able to identify each single web part and save it to our database, allowing us to later provide the web parts inventory for the user. Currently we are trying to subclass the PersonalizationState so we can save the personalization data in a non binary for...

can i drag an image from one web part to another web part
hi can i drag an image from one web part to another web part i.e if i am having an image in one web part i must drag the web part and drop it in the other web part  is it possible or not pls tell me if possible give me how thanks Hi, The image control is also a standard control. WebPartManager will wrap it as a genericWebParts. What you are draging is a WebPart, not a image control. I know what you want is discarding the frame border of the WebPart control, actually you can achieve it by setting the ChromeType property of WebPart to PartChromeType.None...

copy data from one web page to another??
hello I have two different web page running on my pc. one is made of asp and another is java. Both web page has following fields; 1. Name 2. Address 3. Country. My target is  to click a button on the asp page and data of the  name. address and country field will be copied to the respective field of java web page. How can i do that? is there any help?     Assuming you mean that the button starts up the java web page, the simplest way would be to pass that data as parameters in the url. If the java web page is started by the user at some later point in time, y...

can i drag the selected value of dropdown list in one web part to another web part
hi, supose i am having time displaying in on webpart can i drag the value of time to another web part and and display the time is: and the value draged from the other webpart so i want to drag the value year and population into antoher web part and according to that the grap must appear i.e what  i exactly want is i must drag some value from one webpart to onother webpart and according to event some thing must happen in another web part   Hi, The problem has been replied in the following post: http://forums.asp.net/t/1141884.aspx But from the title you described, do ...

Best way of passing a parameter from one web page to another with hyperlink ???
Hello. I'm new to ASP.Net and have a page1 which has a table of images derived from a database throught a dataset. Each image in the table is created by the following code as it loops through the dataset:*****literal1.text +="<td valign='middle' align='center'>" & _                        "<a href=" & FileName & " target=""_blank""><img src=" & _               ...

Need a way to move files from one folder to another using a web page.
I have a web page that tracks a list of zip files in a sql server database.  What i need is to actually move a list of zip files from a master list to sub folder.  Is there a control that i can do this with?  Any suggestions on even a way to get started on this would be greatly appreciated, i don't even know what to look up to try and learn how to do it.  Take a look at: http://www.codeproject.com/aspnet/WebFileManager.asp JeffPlease: Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved...

Web resources about - Simple way to copy web part personalization info from one page to another. - asp.net.personalization

Personalized Gifts from Personalization Mall
Personalization Mall offers personalized gifts for all events and occasions. Find personalized gift ideas for Christmas, weddings, birthdays, ...

Personalization - Wikipedia, the free encyclopedia
Personalization involves using technology to accommodate the differences between individuals. Once confined mainly to the Web , it is increasingly ...

Rotten Tomatoes Adopts Facebook's Instant Personalization
Film review website Rotten Tomatoes has integrated Facebook’s Instant Personalization so that you can get movie recommendations from your friends. ...

A Look At Facebook’s Three Instant Personalization Partners: Yelp, Pandora, Docs.com
... Like button and the Open Graph API, the company would also be working more closely with a select group of outside partners on “instant personalization” ...

Twitter Engineering: Discover: Improved personalizati
Tuesday, May 1, 2012 Discover: Improved personalization algorithms and real-time indexing We are beginning to roll out a new version of the Discover ...

The Personalization Platform team at Amazon uses Mahout and we're hiring people interested in writing ...
... to say? Join LinkedIn for free to participate in the conversation. When you join, you can comment and post your own discussions. Jeff The Personalization ...

New Pandora iOS app rolling out with emphasis on personalization
Pandora is rolling out an updated version of its iPhone app with a strong emphasis on personalization. Personalized genre and artist suggestions ...

Stitch Fix: Reinventing Retail Through Personalization
... advantage. Dell’s product offering advantage, building to custom order, simultaneously created a business model advantage. Stitch Fix’s personalization ...

J.C. Penney, Kohl's Go for Personalization
... media buys for digital campaigns they hope will prove more efficient. The approach mimics that of Macy's, which has focused on personalization ...

Personalization is a Big Challenge for Digital Marketers
... individual or small group. According to an infographic from mobile marketing platform Kahuna , marketers still struggle with effective personalization ...

Resources last updated: 1/1/2016 10:12:32 AM