The webpart personalization can be disabled using:
1) Set Enabled property of the Webpart manater personalization provider:
WebPartManager1.Personalization.Enabled = false;
2) Disable it while declaring the webpart manager in the .aspx page
<asp:webpartmanager runat="server" id="wpmgr1"
personalization-enabled="false" />
Friday, May 2, 2008
Webpart personalization infrastructure
Read the following post which is mostly taken from MSDN, if you are having problem due to ASP.NET personalization provider. This might be required when you are trying to dynamically add/delete webparts and the inconsistent behaviour is observed; specifically when user logs in.
WebPartPersonalization implements low level personalization infrastructure.
This class implements the logic required to carry out lower-level personalization operations. Although the WebPartManager class manages the high-level life cycle of personalization, it is the WebPartPersonalization class that is responsible for actually implementing the physical steps necessary to carry out specific personalization actions. The WebPartPersonalization class in turn relies on an implementation of PersonalizationProvider to communicate with the underlying data store for personalization information.
The WebPartPersonalization class works closely with a WebPartManager control and the rest of the personalization infrastructure.
If you want to create a personalization subsystem significantly different from that provided by the WebPartPersonalization and the WebPartManager classes, you should create a custom WebPartPersonalization implementation by deriving from WebPartPersonalization and add your own custom logic. Then create a custom WebPartManager implementation by deriving from WebPartManager, add your own custom logic, and override the CreatePersonalization method to return your custom WebPartPersonalization implementation. Because a WebPartManager control makes requests to the personalization infrastructure by way of a WebPartPersonalization instance, the WebPartManager control does not directly interact with or hold references to PersonalizationProvider implementations.
WebPartPersonalization implements low level personalization infrastructure.
This class implements the logic required to carry out lower-level personalization operations. Although the WebPartManager class manages the high-level life cycle of personalization, it is the WebPartPersonalization class that is responsible for actually implementing the physical steps necessary to carry out specific personalization actions. The WebPartPersonalization class in turn relies on an implementation of PersonalizationProvider to communicate with the underlying data store for personalization information.
The WebPartPersonalization class works closely with a WebPartManager control and the rest of the personalization infrastructure.
If you want to create a personalization subsystem significantly different from that provided by the WebPartPersonalization and the WebPartManager classes, you should create a custom WebPartPersonalization implementation by deriving from WebPartPersonalization and add your own custom logic. Then create a custom WebPartManager implementation by deriving from WebPartManager, add your own custom logic, and override the CreatePersonalization method to return your custom WebPartPersonalization implementation. Because a WebPartManager control makes requests to the personalization infrastructure by way of a WebPartPersonalization instance, the WebPartManager control does not directly interact with or hold references to PersonalizationProvider implementations.
Wednesday, April 16, 2008
Reseting user personalization state
To manage personalization state of users, you must use the PersonalizationAdministration class. The following example shows how te reset state of the current user:
To reset state of a particular user, use the following code snippet:
For managing user state, refer to http://msdn2.microsoft.com/en-us/library/ms366517.aspx
WebPartManager mgr = WebPartManager.GetCurrentWebPartManager(Page);
mgr.Personalization.ResetPersonalizationState();
To reset state of a particular user, use the following code snippet:
For managing user state, refer to http://msdn2.microsoft.com/en-us/library/ms366517.aspx
// Reset the user.
if (! PersonalizationAdministration.ResetUserState("~/Default.aspx", txtUser.Text))
{
Response.Write("The user could not be found or the user has not personalized this page");
}
Wednesday, April 9, 2008
IsInRole issue with FormsAuthentication
If rolemanager is enabled in the web.config, the GenericPrinciple is automatically cast to RolePrincipal dismissing all of the GenericPrincipal's previous set roles. To disable this automatic cast, disable rolemanager in the web.config.
<rolemanager enabled = "false">
<rolemanager enabled = "false">
Friday, April 4, 2008
Reading/Writing Excel in C# using Interop
Add references to :
Microsoft Excel 10.0/11 Object Library using "add reference->com" tab. The following code shows example of reading and writing the xls:
Microsoft Excel 10.0/11 Object Library using "add reference->com" tab. The following code shows example of reading and writing the xls:
using System;
using System.Collections.Generic;
using System.Text;
using Excel;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string path = @"C:\Documents and Settings\shivps\Desktop\cbit_codef\CBIT_CODEF\New Microsoft Excel Worksheet.xls";
Excel.ApplicationClass app = new ApplicationClass();
app.ShowWindowsInTaskbar = false;
Excel.Workbook wb = app.Workbooks.Open(
path,
0,
false,
5,
"",
"",
true,
Excel.XlPlatform.xlWindows,
"\t",
true,
false,
0,
true,
1,
0);
Excel.Worksheet wsAuthor = null;
foreach (Excel.Worksheet ws in wb.Worksheets)
{
if (string.Compare("author", ws.Name, true) == 0)
{
wsAuthor = ws;
break;
}
}
// read all records
int row = 2; // leave first row
while (true)
{
if (((Excel.Range)wsAuthor.Cells[row, 1]).Value2 == null ||
((Excel.Range)wsAuthor.Cells[row, 2]).Value2 == null ||
((Excel.Range)wsAuthor.Cells[row, 3]).Value2 == null ||
((Excel.Range)wsAuthor.Cells[row, 4]).Value2 == null)
{
break;
}
string first = ((Excel.Range)wsAuthor.Cells[row, 1]).Value2.ToString();
string second = ((Excel.Range)wsAuthor.Cells[row, 2]).Value2.ToString();
string login = ((Excel.Range)wsAuthor.Cells[row, 3]).Value2.ToString();
string pass = ((Excel.Range)wsAuthor.Cells[row, 4]).Value2.ToString();
// create user
string status = "pass";
string error = "no error";
// update xls
wsAuthor.Cells[row, 5] = status;
wsAuthor.Cells[row, 6] = error;
row++;
}
wb.Save();
wb.Close(false, null, null);
app.Quit();
}
}
}
Wednesday, April 2, 2008
Setting Title of a dynamic created webpart
My portal adds and deleted webparts dynamically. I was facing difficulty in setting title of dynamically created webparts. Most of the methods somehow did not work. The following did work for me:
Control c = LoadControl(controlName);
c.ID =id;
wp = WebPartManager1.CreateWebPart(c);
this.WebPartManager1.AddWebPart(wp, wz, index);
wz.WebParts[index].Title = title;
Control c = LoadControl(controlName);
c.ID =id;
wp = WebPartManager1.CreateWebPart(c);
this.WebPartManager1.AddWebPart(wp, wz, index);
wz.WebParts[index].Title = title;
Tuesday, April 1, 2008
Dynamic Webparts: missed events and twice load issue
While developing a portal which has dynamic webparts created, it was observed that control events were not firing. Also page_load function was called more than once. These issues got resolved on setting the personalization state dirty after adding or deleting a webpart. The personalization state can be set Dirty by calling WebPartManager SetPersonalizationDirty function. Since this method is protected, it can not be called directly. To call this function, a custom WebPartManager is required. The following explains it.
1) Create a custom WebPartManager which exposes only a single function SetDirty.
2) Use the custom webpart in the page as given below:
<%@ Register Namespace="Samples.AspNet.CS.Controls" TagPrefix="sample" %>
...
<sample:NewWebPartManager ID="WebPartManager1" runat="server" >
</sample:NewWebPartManager>
1) Create a custom WebPartManager which exposes only a single function SetDirty.
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Security.Permissions;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
namespace Samples.AspNet.CS.Controls
{
public class NewWebPartManager : WebPartManager
{
public NewWebPartManager() { }
public void SetDirty()
{
this.SetPersonalizationDirty();
}
}
}
2) Use the custom webpart in the page as given below:
...
Subscribe to:
Posts (Atom)