What Are Web Parts?
Pages: 1, 2, 3, 4
Catalogs
One of the coolest features of Web Parts is that you can allow your users to pick and choose which controls they would like on their page, and where they'd like to put them. To see this at work, open Default.asxp in Source mode and find a Web Part Zone with no controls in it. Delete the Web Part Zone from the column and drag in a Catalog Zone. Switch to Design view and click on your new Catalog Zone and then click the smart tag to set the format to Professional.
Drag a Declarative Catalog Part into the Catalog Zone and click on its smart tag and choose Edit Templates. Next, drag a Calendar control into the Web Parts Template and use its smart tag to format it, and drag a File Upload control into the template. Then use the Declarative Catalog control's smart tag to stop editing the template. Notice that your two controls are marked "untitled." Switch to Source view, find the Calendar, and add the clever title "Calendar" as shown in this snippet:
<ZoneTemplate>
<asp:DeclarativeCatalogPart ID="DeclarativeCatalogPart1" runat="server">
<WebPartsTemplate>
<asp:Calendar> Title= "Calendar" ID="Calendar1" runat="server" BackColor="White" BorderColor="#999999"
Add a title to the File Upload control as well. Your Catalog Zone control should look more or less like Figure 8.

Figure 8. Catalog Zone -- two controls
Return to source code. Examine the Catalog Zone carefully and you'll see that there is a Zone Template element, within which is a Declarative Catalog Part, within which is a WebPartsTemplate, which in turn holds both the Calendar and the File Upload controls. Find the closing tag for the Declarative Catalog Part, and in between that closing tag and the tag that closes the Zone Template, drag a Page Catalog Part control. This latter control will list the Web Parts on the page and will allow the user to reopen Web Parts that were closed (amazingly, there is no other way for the user to do so!).
Run the application and choose Catalog from the Display Mode drop down. The Catalog Zone has an upper part and a lower part. The upper part tells you that the Declarative Catalog has two items and the Page Catalog has zero items. The lower portion displays the Declarative Catalog. Add a Calendar control to Web Part Zone 2 by checking Add A Calendar as shown in Figure 9.

Figure 9. Add a Catalog Part
When you click Add, the calendar appears in Web Part Zone 2 as the user hoped.
Showing Closed Controls
Click on Browse mode. You should have three controls showing (Today's News, Favorite Books, and Calendar). Click on the menus on each in turn: close Today's News and Favorite Books, and minimize the Calendar. While the menu on Calendar lets you restore it, Today's News and Favorite Books are gone!
To restore them, switch to Catalog mode and notice that the Page Catalog link now shows that there are two controls available. Click the link and select each control in turn and restore it (you can add it to whichever zone you'd like). Switch back to browse mode and the missing controls are back <whew!>.
Jesse Liberty is a senior program manager for Microsoft Silverlight where he is responsible for the creation of tutorials, videos and other content to facilitate the learning and use of Silverlight. Jesse is well known in the industry in part because of his many bestselling books, including O'Reilly Media's Programming .NET 3.5, Programming C# 3.0, Learning ASP.NET with AJAX and the soon to be published Programming Silverlight.
Return to the Windows DevCenter.
You must be logged in to the O'Reilly Network to post a talkback.
Showing messages 1 through 9 of 9.
-
Can't get beyond Browse mode
2007-06-04 09:33:20 PongGod [Reply | View]
When I run the application per the instructions associated with "Figure 5", the only option I have in the Display Mode dropdown is "Browse", not "Design" or "Edit". Is there something that is presumed to be configured a particular way that I am overlooking?
- Robert - -
Can't get beyond Browse mode
2007-06-29 15:12:30 rouxmohammed [Reply | View]
Seems like you missing "InitComplete" methode in your code behind of DisplayModeMenu.ascx.
public void InitComplete(object sender, System.EventArgs e)
{
webPartManager = WebPartManager.GetCurrentWebPartManager(Page);
String browseModeName = WebPartManager.BrowseDisplayMode.Name;
foreach (WebPartDisplayMode mode in
webPartManager.SupportedDisplayModes)
{
String modeName = mode.Name;
if (mode.IsEnabled(webPartManager))
{
ListItem listItem = new ListItem(modeName, modeName);
ddlDisplayMode.Items.Add(listItem);
}
}
}
-
A Few Suggestions
2007-05-23 10:34:58 CodeHunter1 [Reply | View]
I have just completed your sample application. Very well presented and easy to understand article and kudos for that.
There are a couple of issues though that you should probably address in future articles on this or other ASP.NET sample applications that would avoid reader confusion.
- Keep Assumptions to a minimum. Where you must use assumptions inform the reader that you are using an assumption. for example not every developers environment is going to include SQL Express, so it might be a good idea to tell the user that you are assuming that a local version of SQL Express Database is assumed for connectivity purposes
- If a particular methodology or technology is expected in order to complete the sample application e.g. only works with IE6 and not with Firefox tell the user this up front so that they can ensure they have the necessary tools on hand to complete the sample application for themselves. No one likes a sample application that fails to compile or that errors out due to differences in environment.
- Specifically when dealing with ASP.NET 2.0 and Visual Studio 2005 to develop web applications that use personalization let the user know that he will either have to define his own Provider and data store or if she uses the default aspnetdb that she will need to use the aspnet_regsql.exe tool prior to building the application and running it for the first time
Just my $0.02
-
Error
2006-11-09 08:08:48 Bassir [Reply | View]
Hi
Doing your aplication example my VS2005 has found 1 error.Can you help me to resolve it?
Error:Server Error in '/WebSite1' Application.
--------------------------------------------------------------------------------
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)
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
SQLExpress database file auto-creation error:
The connection string specifies a local Sql Server Express instance using a database location within the applications App_Data directory. The provider attempted to automatically create the application services database because the provider determined that the database does not exist. The following configuration requirements are necessary to successfully check for existence of the application services database and automatically create the application services database:
If the applications App_Data directory does not already exist, the web server account must have read and write access to the applications directory. This is necessary because the web server account will automatically create the App_Data directory if it does not already exist.
If the applications App_Data directory already exists, the web server account only requires read and write access to the applications App_Data directory. This is necessary because the web server account will attempt to verify that the Sql Server Express database already exists within the applications App_Data directory. Revoking read access on the App_Data directory from the web server account will prevent the provider from correctly determining if the Sql Server Express database already exists. This will cause an error when the provider attempts to create a duplicate of an already existing database. Write access is required because the web server accounts credentials are used when creating the new database.
Sql Server Express must be installed on the machine.
The process identity for the web server account must have a local user profile. See the readme document for details on how to create a local user profile for both machine and domain accounts.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[SqlException (0x80131904): 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)]
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +117
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +346
System.Data.SqlClient.TdsParser.Connect(Boolean& useFailoverPartner, Boolean& failoverDemandDone, String host, String failoverPartner, String protocol, SqlInternalConnectionTds connHandler, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject, Boolean aliasLookup) +1093
System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +1084
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +272
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +355
System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup) +91
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +115
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +122
System.Data.SqlClient.SqlConnection.Open() +229
System.Web.Management.SqlServices.GetSqlConnection(String server, String user, String password, Boolean trusted, String connectionString) +110
[HttpException (0x80004005): Unable to connect to SQL Server database.]
System.Web.Management.SqlServices.GetSqlConnection(String server, String user, String password, Boolean trusted, String connectionString) +181
System.Web.Management.SqlServices.SetupApplicationServices(String server, String user, String password, Boolean trusted, String connectionString, String database, String dbFileName, SqlFeatures features, Boolean install) +167
System.Web.Management.SqlServices.Install(String database, String dbFileName, String connectionString) +46
System.Web.DataAccess.SqlConnectionHelper.CreateMdfFile(String fullFileName, String dataDir, String connectionString) +681
-
Error
2007-09-18 03:43:41 Salini [Reply | View]
If we don't disable
'Personalization-Enabled' attribute of webpartmanager, it is assumed to be true. In that case, it will try to locate the DB in SQL Server 2005 by default for personalization.
Hence we have to set the Personalization-Enabled="false"
like,
<asp:WebPartManager ID="webpartManagerSampleSite" runat="server" Personalization-Enabled="false"> </asp:WebPartManager>
-
RE:Web Parts in ASP.NET 2.0
2006-03-03 03:55:10 Vimall [Reply | View]
Nice article, but you can also provide information about the supportability in various browsers. Because, in Design mode -- the drag & drop functionality is not working in Firefox & others too except IE. Can you mention, what is the work around for this. -
RE:Web Parts in ASP.NET 2.0
2006-05-04 08:34:27 AlexDevNet [Reply | View]
Yoy can add drag & drop functionality with Firefox using Atlas. All u ned to do is add in your Web.Config some atlas tags.
Here how to do it http://blogs.neudesic.com/blogs/david_barkol/archive/2006/03/22/82.aspx
____________________________
Alexey Agapov
http://devtalk.blogdrive.com






then it throws a exception that is already posted in previous thread...which is
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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: 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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[SqlException (0x80131904): 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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)]
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +800131
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +186
System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject) +737554
System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject) +114
System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart) +421
System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +181
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +173
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +133
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +30
System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +424
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66
System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +494
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +82
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +105
System.Data.SqlClient.SqlConnection.Open() +111
System.Web.DataAccess.SqlConnectionHolder.Open(HttpContext context, Boolean revertImpersonate) +84
System.Web.DataAccess.SqlConnectionHelper.GetConnection(String connectionString, Boolean revertImpersonation) +197
System.Web.UI.WebControls.WebParts.SqlPersonalizationProvider.GetConnectionHolder() +16
System.Web.UI.WebControls.WebParts.SqlPersonalizationProvider.LoadPersonalizationBlobs(WebPartManager webPartManager, String path, String userName, Byte[]& sharedDataBlob, Byte[]& userDataBlob) +195
System.Web.UI.WebControls.WebParts.PersonalizationProvider.LoadPersonalizationState(WebPartManager webPartManager, Boolean ignoreCurrentUser) +95
System.Web.UI.WebControls.WebParts.WebPartPersonalization.Load() +105
System.Web.UI.WebControls.WebParts.WebPartManager.OnInit(EventArgs e) +497
System.Web.UI.Control.InitRecursive(Control namingContainer) +321
System.Web.UI.Control.InitRecursive(Control namingContainer) +198
System.Web.UI.Control.InitRecursive(Control namingContainer) +198
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +834
Im using VS2008...any suggestions