Wednesday, June 8, 2011

Using Webpartzone,WebPartmanager



First of all you should download the Asp.Net future July 2007 Plug-in to use Web-part
"http://www.microsoft.com/downloads/en/details.aspx?FamilyId=A5189BCB-EF81-4C12-9733-E294D13A58E6&displaylang=en"
and install it. Now run the Visual Studio 2008-2010.
Create a new WebSite project and open default.aspx page.
In 2008 Toolbox you can see Asp.net Future which is automatically added but in 2010 you should right click on the Toolbox and select "Choose Items" and then click the "Browse" and go to the following location " C:\Program Files\Microsoft ASP.NET\ASP.NET Futures July 2007\v1.3.61025\3.5" and select all components and then press OK.
Now you can see the Asp.Net Future tab in Toolbox.
now drag the WebPartManager and then WebPartZone but don't forget the "scriptmanager"


in the below example i am using the ASP.net Member Provider for login and register the member and maintain its session and its webpart setting. So go to the
C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regsql.exe
if you are using VS2010 other find aspnet_regsql in the above folder.
and run it and


See the below example
Design Code







CS Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
//using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.Web.Preview.UI.Controls.WebParts;

namespace AspWebPart
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (WebPartManager1.Personalization.Scope == System.Web.UI.WebControls.WebParts.PersonalizationScope.User)
{
if (WebPartManager1.Personalization.CanEnterSharedScope)
{
WebPartManager1.Personalization.ToggleScope();

}
}

}



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

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

protected void btnDesign_Click(object sender, EventArgs e)
{
WebPartManager1.DisplayMode = WebPartManager.DesignDisplayMode;
}

protected void btnCatalog_Click(object sender, EventArgs e)
{
WebPartManager1.DisplayMode = WebPartManager.CatalogDisplayMode;
}


}
}



Web.Config File

No comments:

Post a Comment