ASP.NET 2.0 Web Parts Portal - Part 1 - The Basics
Portal sites are created to provide the ultimate in flexibility and personalization. Whether for a company intranet or a public website, this type of site allows administrators or users to quickly customize what and where content is displayed by adding, removing, and drag-and-drop relocating web parts. For this blog series, I'll be creating a portal website using .NET web parts, and I'll walk you through the steps required to create your own web parts enabled site.
PART 1: Set up the basics
Create a new ASP.NET web project. I'll place mine at C:\Inetpub\wwwroot\ThePortal. Most web part pages are held together using basic HTML tables. I'll add a 2 x 4 table via the Layout --> Insert Table. Viewing source, I'll remove the bottom right cell and add a rowspan=2 property to the top right cell. The right hand cell will contain the controls our visitors will use to customize their web page.
Adding the big guy: All web part pages must have exactly one WebPartManager control. This control will oversee all web part activity, including managing all web zones and the connections between these zones. Keep in mind that if you are using Master Pages and are planning on using web parts in various content pages, you'll want to place the WebPartManager in the Master page, and reference it as needed from the content pages.
After you've added the WebPartManager, you can start to drop WebPartZone controls into each table cell. Leave the right cell blank for now. WebPartZones define independent sections of a web part portal; any content inside of a WebPartZone will apply the same styles and move as one around the page.
For each WebPartZone, select the formatting drop down menu at the top right of each control, and select Auto Format. Choose your favorite style to apply to each zone. Choose different styles for some of the zones, as we'll use this a way to understand what happens when content moves from one zone to the next.
Drop some of your favorite controls into the WebPartZones. Use panels and placeholder controls to group multiple controls together. .NET adds a GenericWebPart wrapper control around each web server control, allowing them to share some behavior and attributes of WebPart Controls. One example of this is the Title attribute, which you'll want to set for each of the controls you've added, such as:
<asp:Panel id=Panel1 title=Newsletter" ...
Don't worry if Visual Studio complains that a panel doesn't support a Title attribute, the GenericWebPart will when the page is run.
When you compile and run your project, you can see how your controls are rendered as sections of the portal. Notice how applying separate styles to each zone has changed the appearance of the controls. We'll work on adding more useful controls, and cleaning up the portal in the upcoming segments. Make sure you play with minimizing and restoring some of the zones when you view the page. We'll enhance the personalization features & add a web part catalog in the next segment.
Minimize some of the controls, then leave the page. When you return, your settings will be preserved. Your local setttings are saved in the ASPNETDB database inside the AppCode folder, inside the aspnet_PersonalizationPerUser table. Notice that if you close one of the parts, it completely disappears from the page. You can delete your user's rows from this table to reset any changes you've made to the page. We'll make this much easier to do from the page itself in the coming days.
I apologize if this seciton was over-simplified; I wanted to make sure everyone had a basic understanding of how to set up a web part project. I'll delve much deeper in the coming days...we'll explore adding/removing web parts at run time, rearranging the portal, saving user settings, web user controls, custom controls, master-child web part connections and more.