Introduction:
Portal web sites such as MY MSN and MSN Spaces, often organize their data into discrete units that support a degree of personalization. Information is organized into standalone parts [WebParts], and users can rearrange those parts to suit their individual working styles. Such personalization also lets users hide parts that contain information in which they have no interest. What's more, users can save their settings so that the site will remember their preferences the next time they visit the site. In ASP.NET 2.0, you can now build web portals that offer this kind of modularization of information and personalization using the new Web Parts Framework.
Scope of this Tutorial:
Here we will see how to add web parts to a web part page. Developing advanced WebParts from scratch is out of this tutorial scope. This tutorial also may has subsequent tutorial that explains more about Web Parts Framework.
Assumptions:
This tutorial assumes you are familiar with Data Access Controls and Data Binding Controls such as SqlDataSource and GridView. Also it requires SQL Sever 2005 Express Edition and Visual Web Developer. If you don't have SQL Server Express 2005, install ASPNETDB in your SQL Server instance using aspnet_regsql tool. and configure your application to use this instance as your personalization provider.
How to create WebParts Page:
To create a WebParts Page, you need to work with a specific ASP.Net 2.0 Controls:
- WebPartManager Control, which manages all Web Parts controls on a WebParts Page and must be the first control that you add to the page.
-
WebPartZone Control, which contains and provides overall layout for the Web Part controls that compose the main UI of a page. This control serves as an anchor for Web Part controls. Multiple controls of this control forms the WebParts Page.
The WebPartZone may contains one or more WebParts.
To create a WebPart Page:
-
Create a home page for the Web Parts. Launch Visual Studio 2005 and create a new web site project.
-
While in design view, drag and drop a WebPartManager control from the toolbox (under the WebParts tab) onto the default Web Form, rename it to wpManager.
-
From Layout menu item, select Insert Table, insert table with 3 columns and 1 row. This is where the Web Parts on your page are to be located.
-
Drag and drop a WebPartZone control from the Toolbox (under the WebParts tab) into each of the table's three cells. Each WebPartZone control will serve as the docking area for one or more Web Parts. A Web Part zone is an area where Web Parts are anchored. It also defines the default layout and appearance of each Web Part within that zone.
-
Set the ID property for each WebPartZone Control to be wpzLeft, wpzMiddle and wpzRight. Then for each one set the Auto format to Professional.
-
Save your form.
You have created your WebParts Page. Now you want to add WebParts to your page, and manage them at run time so you can rearrange WebParts positions.
Next we will add 2 WebParts, one will display Information from SQL Server Database. While the other one will display data from XML file.
Adding WebParts to the WebParts Page:
-
Drag and drop SqlDataSource control into you Web Form, rename it to sdsTitles. Configure it to retrieve data from Titles Table in Pubs Database. [you can use SQL Server 2000 or SQL Server 2005 any Edition].

-
Drag and drop GridView into wpzLeft WebPartZone control, rename it to gvTitles. Configure gvTitles to user sdsTitles as a Data Source.
-
Switch to the Source View and add title attribute to the GridVew -gvTitles- control and set its value to "Titles".

Set Auto format for the GridView control to classic, also set the Paging and Sorting options, and set PageSize property to 5.
-
Drag and drop XmlDataSource control to your Web Form, rename it to xdsRSS. Configure it to use the RSS.xml that is attached with the demo project, or use any other well-formed XML file you wish.
-
Drag and drop DataList into wpzMiddle, and rename it to dlstRss. Switch to source view and configure your DataList as the following.
-
Now test your page. You will be able to see the two Web Parts, minimize them or close them only. On the following steps you'll be able to create to move them and rearrange them.
-
Drag and drop LinkBotton to your page, not into any Web Part Zone, rename it to btnDesign. and set its text property to "Design View"
- Double click on the button to add click event handler, then add the following code in the event handler method:
protected void btnDesign_Click(object sender, EventArgs e)
{if (btnDesign.Text == "Design View")
{wpManager.DisplayMode = WebPartManager.DesignDisplayMode;
}
btnDesign.Text = "Page View";
else
{wpManager.DisplayMode = WebPartManager.BrowseDisplayMode;
}
btnDesign.Text = "Design View";}
- Now Run your application, note when you click on the button you can now rearrange you web parts on the page.

Conclusion:
Now have explored the basics of creating WebParts Page and adding WebParts to it at design/development time. This demo showed that every Control in ASP.Net 2.0 can be a web part without customization or extra code. Same for Custom User Controls; as you can put any controls we have just worked with into a user control, then drag and drop you user control into the WebPartZone and you will get your user control as WebPart.
WebParts is special kind of WebServer Controls. It has more advanced feature. Hope we will be able to discuss them in subsequent tutorials.
Read Part II : Working with WebParts Page, WebPart Zones & WebParts

Chandra ShekharPosted Jun 26, 2012, 3:21 AM
ASP.NET and Ajax. All about update panels, web methods, page methods and jQuery
Suleyman KosePosted Apr 26, 2012, 5:55 PM
would friends help me asp.net and web part please?I am a student.Does Friends do asp.net and web part project or give link?
prajakta zendePosted Sep 16, 2011, 3:57 AM
U have not uploaded database in this. Its not working
surya maliniPosted Jan 23, 2010, 6:47 AM
Hello sir, Thank u very much. Can i know some more details like how to create webpages and its fields for Customer Relationship Management(CRM). Moreover, Iam in position to use the dotnet 3.5 framework and Sql Server as backend. Please help me. My mail: [email protected]
sanjeevPosted Dec 18, 2008, 3:45 AM
Hi, I was trying the web part zone control in my application. I have followed the exact steps given in your article (Adding WebPartManager, WebPartZone, ASP Controls). I can see the Verb Menu icon at the design time. But when I am running the application, I can't see the verb menu beside the title. At the execution of following line wpManager.DisplayMode = WebPartManager.DesignDisplayMode; DOT NET throws an error The specified display mode is currently disabled on this page. Make sure personalization is enabled for the current user. Please assist. Thanks in advance
batra amitPosted Mar 19, 2008, 3:43 AM
How to open word document one webpart as a viewer on other webparts there is link of that document
sandeepPosted Jul 26, 2007, 9:32 AM
I am having trouble displaying the server contol(Label) text added to a web part dynamically/programmatically. If I add a client side "title" attribute then the title is being displayed but not the actual text. I want ot add other contols like asp:Table. Below is my code. Please let me know what I am missing. I am adding this on page_init Label lblNodeValue = new Label(); lblNodeValue.ID = "lblNode"; lblNodeValue.Text = "Node1"; lblNodeValue.Attributes.Add("Title", "FirstNode"); GenericWebPart gwp = WebPartManager1.CreateWebPart(lblNodeValue); WebPartManager1.AddWebPart(gwp, WebPartZone1, 0);
ganesh kumarPosted May 8, 2007, 1:03 AM
how we can store the individual settings for different user who did their own settings.
vikas kudyarPosted Apr 27, 2007, 8:44 AM
I have a visual studio.Net on my system and i am working to minimizing a webpart in Share POint portal server But I am not able to do that .will you please help me with that i ll be thankful.
frankiePosted Feb 26, 2007, 11:44 PM
Hi, I read the article and try the example, but i can't get it working. Below is the error message i've got. An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) When i add gridview and configured to the new data source, it was working perfectly. all data were retrieved, but whenever i run the application. I'll get the above error message. Please help Thanks
Johan Van DykPosted Feb 20, 2007, 6:08 AM
I worked through the tutorial and all worked well. I noticed that a SQLExpress database is created when running this tutorial. My question is this: What is needed to NOT use SQLExpress but rather SQL 2000 or SQL 2005. Please be specific as I am a beginner. Thanks in advance Johan PS: Great tutorial Muhammad!
Bob SieloffeditedPosted Oct 13, 2006, 3:43 PMEdited Oct 13, 2006, 4:43 PM
I seem to be having issues with the 8th step. My background is more in System's engineering so perhpas I am missing something basic. This is the code behind my link button. Does it look correct? An "end of statement" comment is shown when I mouse over the "Protected void..." statement. Also, I was hoping to design web parts for SPS 2003. Is there a good article that describes how to design web parts for SPS? Thank you for the great tutorial. It has been fun and I learned somthing new. ====== Protected Sub btnDesign_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDesign.Click Protected void btnDesign_Click(object sender, EventArgs e) { if (btnDesign.Text == "Design View") { wpManager.DisplayMode = WebPartManager.DesignDisplayMode; btnDesign.Text = "Page View"; } Else { wpManager.DisplayMode = WebPartManager.BrowseDisplayMode; btnDesign.Text = "Design View"; } } End Sub
rajPosted Aug 2, 2006, 5:49 AM
hai I had tried the article to create a simple webpart appliation. i tried the exact code but for me the colse verb,minimizeverbs are not comeing. why it is happeing.
Moses SolimaneditedPosted Aug 1, 2006, 6:14 PMEdited Oct 10, 2006, 8:18 AM
You cannot use your .Net 2.0 webparts in SPS 2003. there is another tool for VS.NET 2003. if you are using SPS 2003 please inform me and I'll submit to best resources for it
manh dung nguyenPosted Jul 5, 2006, 10:42 PM
hi mosessaur i create webpart using vs.net(webform) but i don't know add webpart to Sharepoint? could you hellp me? .thank!
Chintan JhaverieditedPosted Jun 12, 2006, 5:12 AMEdited Oct 10, 2006, 1:57 AM
Hi, I was trying the web part zone control in my application. I have followed the exact steps given in your article (Adding WebPartManager, WebPartZone, ASP Controls). I can see the Verb Menu icon at the design time. But when I am running the application, I can't see the verb menu beside the title. At the execution of following line wpManager.DisplayMode = WebPartManager.DesignDisplayMode; DOT NET throws an error The specified display mode is currently disabled on this page. Make sure personalization is enabled for the current user. Please assist. Thanks in advance.
r peditedPosted Apr 19, 2006, 9:07 AMEdited Aug 8, 2006, 10:50 AM
hi i have vs2003 on my machine & i want to creat a login page/control as a web part so when user use my url he will see my login page & when he get authenicated he will be able to access my web otherwise not. so if you have code for this type of application please send me. thanking you,
bashmohandesPosted Mar 7, 2006, 9:17 PM
I think the customizations in the Web Parts are only for logged in users, because When I try to use this without logging in it keeps throwing errors, so if there is any other way to make it for anyone please inform... Thanks for your great article Mohammed Hossam [email protected] (MSN Messenger only) [email protected] Mailing