Friday, May 23, 2008

WebParts in Asp .Net

Before speaking about WebParts in Asp .Net let me speak a bit about iGoogle. Following is my iGoogle page.



















Here I can decide on what to appear on my page. I can add new Gadgets, remove Gadgets and change the location of gadgets.

Similar service are provided by Microsoft in my.msn.com as show in the figure.



















Web Parts
is Microsoft technology for creating personalized pages as seen in iGoogle. This is a part of Microsoft Portal Framework.

Start a new Asp .Net Project. Add a Table with 4 columns and 1 row.
Add a WebPartManager to the form.

Add a WebPartZone to each Table Data.

Into the first WebPart Zone add a Calendar.
Since the calendar is place inside a WebPart zone you will get an extender property called Title. Set an appropriate title.

If you run the application you will see extra menu options for Calendar contol as shown in the exhibit.
























Now you are in Browser Display Mode.

If you select the minimize option the the calendar will be minimized and next time you open the page the minimized state will be persisted.













WebParts Design Display Mode
WebParts supports multiple display mode. In Design Display Mode you can drag a control from one webpart zone to another.

Place a Command Button on the existing form. Change its text to Design. On clicking the Design Button you want to change the display mode to Design Display Mode.
Here is the code

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

Now you can drag a control from one WebPartZone to another as shown in the figure below.

















CatalogDispalyMode for Adding Controls to WebPartZone

If you close the Calendar by select Close menu from the control there is no way the have the control back. Also you might want to add new Control (widgets) to a zone as Add Stuff option in iGoogle. For doing that you can use the CatalogZone and DeclarativeCatalogPart controls and setting the Display mode to Catalog Display mode.

So add a CatalogZone to the page. Add a DeclarativeCatalogPart to the CatalogZone. Select Edit Template from the Smart tag of DeclarativeCatalogPart.














Cut and past the calender control into the DeclarativeCatalogPart.

Add a Command Button give a text Catalog. On clicking the button you have change the Display mode to CatalogDisplay Mode.

Here is the code:
protected void btnCatalog_Click(object sender, EventArgs e)
{
WebPartManager1.DisplayMode = WebPartManager.CatalogDisplayMode;
}

Now when you click the button you will see the Catalog zone. From the catalog zone you can select the control and the WebPartZone to which you want to add the control.
















Now we can implement the BrowseDisplayMode which is the mode for end user browsing.
So Place another TextBox. Set the Text Propterty to Browser and write the following code:

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

WebParts and ASPNETDB Database
You might be wondering the the data is getting persisted. It is in the ASPNETDB.MDF file system database that is getting created inside App_Data folder of the project. The information is stored in aspnet_PersonalizationPerUser table as shown in the figure below.
















ASPNETDB Database is used in Membership, Profile and WebParts services of Asp .Net 2.0.

Asp.Net 2.0 Master Page and TreeView
Themes in Asp .Net
shalvinpd.blogspot.com

No comments:

Post a Comment