Category Archives: CatalogZone

[RESOLVED] how to change orientation of webparts from vertical to horizontal in catelog zone

dear experts,


by default  closed webparts are listed in catelog zone vertically

for example,

[checkbox]  [webpart 1]

[checkbox]  [webpart 2]

[checkbox]  [webpart 3]


any one guide me which property is used to list them horizontally?

i want them like

[checkbox]  [webpart 1]   [checkbox]  [webpart 2]    [checkbox]  [webpart 3]


any help would be appreciated.


Hi,

You can use

 LayoutOrientation="Horizontal"

Regards
Shabir
<asp:CatalogZone ID="CatalogZone1" runat="server" BackColor="#F7F6F3" BorderColor="#CCCCCC"
                    BorderWidth="1px" Font-Names="Verdana" Padding="6" LayoutOrientation="Horizontal" >
                    <ZoneTemplate>
                    <asp:PageCatalogPart ID="PageCatalogPart1" runat="server" />


                     <asp:DeclarativeCatalogPart ID="DeclarativeCatalogPart1" runat="server"  Title="Web Parts"  LayoutOrientation="Horizontal">
                        <WebPartsTemplate>
                           

                        </WebPartsTemplate>
                   </asp:DeclarativeCatalogPart>




                    </ZoneTemplate>
                    <PartLinkStyle Font-Size="0.8em" />
                    <PartTitleStyle BackColor="#5D7B9D" Font-Bold="True" Font-Size="0.8em" ForeColor="White" />
                    <EditUIStyle Font-Names="Verdana" Font-Size="0.8em" ForeColor="#333333" />
                    <PartStyle BorderColor="#F7F6F3" BorderWidth="5px" />
                    <HeaderVerbStyle Font-Bold="False" Font-Size="0.8em" Font-Underline="False" ForeColor="#333333" />
                    <PartChromeStyle BorderColor="#E2DED6" BorderStyle="Solid" BorderWidth="1px" />
                    <EmptyZoneTextStyle Font-Size="0.8em" ForeColor="#333333" />
                    <SelectedPartLinkStyle Font-Size="0.8em" />
                    <VerbStyle Font-Names="Verdana" Font-Size="0.8em" ForeColor="#333333" />
                    <LabelStyle Font-Size="0.8em" ForeColor="#333333" />
                    <FooterStyle BackColor="#E2DED6" HorizontalAlign="Right" />
                    <HeaderStyle BackColor="#E2DED6" Font-Bold="True" Font-Size="0.8em" ForeColor="#333333" />
                    <InstructionTextStyle Font-Size="0.8em" ForeColor="#333333" />
                </asp:CatalogZone>





Hi,

You can try to set the PartStyle:

<PartStyle
            GridLines="Horizontal"
            HorizontalAlign="Center"
/>

 

Hope this can help you.

[RESOLVED] Web part cannot create the file-based database ASPNETDB.MDF

I get the following error when trying to run the webpart page:

SQLExpress database file auto-creation error:


The connection string specifies a local Sql Server Express instance using a database location within the application's 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:


1. If the application is running on either Windows 7 or Windows Server 2008R2, special configuration steps are necessary to enable automatic creation of the provider database. Additional information is available at: http://go.microsoft.com/fwlink/?LinkId=160102. If the application's App_Data directory does not already exist, the web server account must have read and write access to the application's directory. This is necessary because the web server account will automatically create the App_Data directory if it does not already exist.

2. If the application's App_Data directory already exists, the web server account only requires read and write access to the application's 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 application's 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 account's credentials are used when creating the new database.

3. Sql Server Express must be installed on the machine.

4. 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.

webpart page's .aspx file:

<asp:WebPartManager ID="WebPartManager1" runat="server"></asp:WebPartManager>
    <table style="width: 100%">
        <tr valign="middle" style="background: #00ccff">
            <td colspan="2"><span>Welcom to Web Part Pages!</span></td>
            <td>Menu</td>
        </tr>     
        <tr valign="top">
            <td style="width: 20%"><asp:CatalogZone ID="SimpleCatalog" runat="server"></asp:CatalogZone></td>
            <td style="width: 60%"><asp:WebPartZone ID="MainZone" runat="server"></asp:WebPartZone></td>
            <td style="width: 20%"><asp:WebPartZone ID="HelpZone" runat="server"></asp:WebPartZone></td>
        </tr>   
    </table>

I am using Windows XP Prof.

The application's App_Data directory already exists and is empty. When I view that directory's property in Windows Explorer, it has a check in the box for Read-only. Is that where it should show the box unchecked when the web server account requires to have this directory to have read and write privilege? I try to uncheck that box and Apply, but when I get back to property it's checked again.

Sql Server Express is installed on the machine. I can connect to a default instance via SQL Server Management Studio with no problem.

"The process identity for the web server account must have a local user profile." -- what does this mean and how can I get to the web server account to see what configuration it has?

Thank you.

 

 

I read all solutions from your link and try them all out but none of them works for me. Here's what I try:

I try to follow the suggestion to delete the C:\Documents and Settings\username\Local Settings\Application Data\Microsoft\Microsoft SQL Server Data\SQLEXPRESS directory but I cannot find that folder on my machine. I even search for it and still can't find it.

I cannot find this folder to delete it either:
C:\Documents and Settings\<machine name>\ASPNET\Local Settings\Application Data\Microsoft\Microsoft SQL Server Data.

In Visual Studio, I cannot create new database files either. When I right-click on my app's App_Data folder and choose "Add New Item...", then select "Sql Server Database", I get an error message:
"Connections to SQL Server database files (*.mdf) require SQL Server 2005 Express or SQL Server 2008 Express to be installed and running on the local computer..."


I follow this suggestion: Control Panel -> Administrative Tools -> Services -> right click on SQL Server (SQLEXPRESS) service then Properties -> Then Goto Logon tab -> Select the Local System Account option ->Apply->OK.
I can still connect to SQL via SQL Server Management Studio but NOT from Visual Studio 2010's .net web page.

I follow the suggestion about selecting mixed mode authentication during installation of SQL Server 2008, but that doesn't solve the problem.

There's a suggestion about changing the connection string name to "localsqlserver". I am not sure where to change that. Is it in the web.config file like here?

 

<membership>
			<providers>
				<clear/>
				<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices"
             enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
             maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0"
             passwordAttemptWindow="10" applicationName="/"/>
			</providers>
		</membership>
    
		<profile>
			<providers>
				<clear/>
				<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
			</providers>
		</profile>
    
		<roleManager enabled="false">
			<providers>
				<clear/>
				<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/"/>
				<add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/"/>
			</providers>
		</roleManager>

If it is, I already try  localsqlserver and it doesn't work either. Is there any particular thing that I have to specify in the web.config file?

My web site is in visual studio 2010, all pages except the web part page is connecting to Oracle database. I don't know how the web part page connects to SQL instead of Oracle and whether it's OK to mix pages using Oracle with a web part page that uses SQL.

 

 

pinky8

There's a suggestion about changing the connection string name to "localsqlserver". I am not sure where to change that. Is it in the web.config file like here?

You can set up it under connectionstring tag like:

<connectionStrings>
    <remove name="LocalSQLServer"/>
    <add name="LocalSQLServer" connectionString="YourConnectionString"/>
  </connectionStrings>

pinky8

except the web part page is connecting to Oracle database.

If you want to use Oracle as your Database for personalization then you need to create a custom personalization provider for that.. Check this post: http://forums.asp.net/p/1557127/3839107.aspx

You can also find all the basic things you need to know about WebParts and Personalization here:ASP.NET WebPart FAQ

 

Thank you for the info.

Personalization

I create TextFilePersonalizationProvider.aspx based on http://msdn.microsoft.com/en-us/library/aa479037.aspx and add TextFilePersonalizationProvider class and its content to the code behind. And I create a folder called Personalization_Data under App_Data folder. I'm new to Web Parts and Personalization; I don't know what to do next, how to utilize that class.

It also mentions about adding this to web.config file, and it assumes that TextFilePersonalizationProvider is implemented in an assembly named CustomProviders. What's involved in creating that? thanks.

<configuration>
  <system.web>
    <webParts>
      <personalization
        defaultProvider="AspNetTextFilePersonalizationProvider">
        <providers>
          <add name="AspNetTextFilePersonalizationProvider"
            type="TextFilePersonalizationProvider, CustomProviders"/>
        </providers>
      </personalization>
    </webParts>
</configuration>

 

pinky8

I'm new to Web Parts and Personalization; I don't know what to do next, how to utilize that class.

When you have set up the provider you would use Web Parts as normal.

You say that you are new to Web Parts and Personalization - you do realise that you don't need to create a custom provider to use this system right? Storing the data in a sql database would be better than storing it in a text file unless you have a good reason not to. If you hadn't realised this I would start again to learn how to implement web parts with an introductory tutorial.

pinky8

It also mentions about adding this to web.config file, and it assumes that TextFilePersonalizationProvider is implemented in an assembly named CustomProviders. What's involved in creating that?

You can put the code in your app_code folder and simply replace the "CustomProviders" with "App_Code" and it will work.

If you really want to place this in a separate assembly then you would need to add a Class Library to your project. The name of the class library would become the assembly name at compile time. So name it CustomProviders, put the class in to this library and compile it. This would only really be necessary if you want to redistribute the assembly to different people. In this case I think they are just illustrating that you can put it in its own assembly if you want to. I would personally simply implement it in app_code. I guess thinking about it - web application projects don't have the app_code folder so this is when you would want to put it into an assembly.

I have a web application that has pages that interact with Oracle database to retrieve data from the database and save data to the database. For learning Web Parts, I am adding WebPart.aspx page to the application as below:

<asp:WebPartManager ID="WebPartManager1" runat="server"></asp:WebPartManager>
    <table style="width: 100%">
        <tr valign="middle" style="background: #00ccff">
            <td colspan="2"><span>Welcome to Web Part Pages!</span></td>
            <td>Menu</td>
        </tr>
        <tr valign="top">
            <td style="width: 20%"><asp:CatalogZone ID="SimpleCatalog" runat="server"></asp:CatalogZone></td>
            <td style="width: 60%"><asp:WebPartZone ID="MainZone" runat="server"></asp:WebPartZone></td>
            <td style="width: 20%"><asp:WebPartZone ID="HelpZone" runat="server"></asp:WebPartZone></td>
        </tr>
    </table>

I guess that WebPart.aspx page connect to SQL instead of Oracle. I posted a question about whether I can use Oracle instead of SQL because all of my other pages use Oracle. I was told that if I wanted to use Oracle as my Database for personalization then I need to create a custom personalization provider for that. So I create TextFilePersonalizationProvider.aspx.cs and copy the codes from the given link. Its content is shown below:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration.Provider;
using System.Security.Permissions;
using System.Web.UI.WebControls.WebParts;
using System.Collections.Specialized;
using System.Security.Cryptography;
using System.Text;
using System.IO;

namespace Personalization
{
    public partial class TextFilePersonalizationProvider : PersonalizationProvider
    {
         public override string ApplicationName
        {
            get { throw new NotSupportedException(); }
            set { throw new NotSupportedException(); }
        }

        public override void Initialize(string name, NameValueCollection config)
        {
            // Verify that config isn't null
            if (config == null)
                throw new ArgumentNullException("config");

            // Assign the provider a default name if it doesn't have one
            if (String.IsNullOrEmpty(name))
                name = "TextFilePersonalizationProvider";

            // Add a default "description" attribute to config if the
            // attribute doesn't exist or is empty
            if (string.IsNullOrEmpty(config["description"]))
            {
                config.Remove("description");
                config.Add("description",
                    "Text file personalization provider");
            }

            // Call the base class's Initialize method
            base.Initialize(name, config);

            // Throw an exception if unrecognized attributes remain
            if (config.Count > 0)
            {
                string attr = config.GetKey(0);
                if (!String.IsNullOrEmpty(attr))
                    throw new ProviderException
                        ("Unrecognized attribute: " + attr);
            }

            // Make sure we can read and write files in the
            // ~/App_Data/Personalization_Data directory
            FileIOPermission permission = new FileIOPermission
                (FileIOPermissionAccess.AllAccess,
                HttpContext.Current.Server.MapPath
                ("~/App_Data/Personalization_Data"));
            permission.Demand();
        }

        protected override void LoadPersonalizationBlobs(WebPartManager webPartManager, string path, string userName,
                        ref byte[] sharedDataBlob, ref byte[] userDataBlob)
        {
            // Load shared state
            StreamReader reader1 = null;
            sharedDataBlob = null;

            try
            {
                reader1 = new StreamReader(GetPath(null, path));
                sharedDataBlob = Convert.FromBase64String(reader1.ReadLine());
            }
            catch (FileNotFoundException)
            {
                // Not an error if file doesn't exist
            }
            finally
            {
                if (reader1 != null)
                    reader1.Close();
            }

            // Load private state if userName holds a user name
            if (!String.IsNullOrEmpty(userName))
            {
                StreamReader reader2 = null;
                userDataBlob = null;

                try
                {
                    reader2 = new StreamReader(GetPath(userName, path));
                    userDataBlob = Convert.FromBase64String(reader2.ReadLine());
                }
                catch (FileNotFoundException)
                {
                    // Not an error if file doesn't exist
                }
                finally
                {
                    if (reader2 != null)
                        reader2.Close();
                }
            }
        }

        protected override void ResetPersonalizationBlob(WebPartManager webPartManager, string path, string userName)
        {
            // Delete the specified personalization file
            try
            {
                File.Delete(GetPath(userName, path));
            }
            catch (FileNotFoundException) { }
        }

        protected override void SavePersonalizationBlob(WebPartManager webPartManager, string path, string userName, byte[] dataBlob)
        {
            StreamWriter writer = null;

            try
            {
                writer = new StreamWriter(GetPath(userName, path), false);
                writer.WriteLine(Convert.ToBase64String(dataBlob));
            }
            finally
            {
                if (writer != null)
                    writer.Close();
            }
        }

        public override PersonalizationStateInfoCollection FindState(PersonalizationScope scope, PersonalizationStateQuery query,
                     int pageIndex, int pageSize, out int totalRecords)
        {
            throw new NotSupportedException();
        }

        public override int GetCountOfState(PersonalizationScope scope, PersonalizationStateQuery query)
        {
            throw new NotSupportedException();
        }

        public override int ResetState(PersonalizationScope scope, string[] paths, string[] usernames)
        {
            throw new NotSupportedException();
        }

        public override int ResetUserState(string path, DateTime userInactiveSinceDate)
        {
            throw new NotSupportedException();
        }

        private string GetPath(string userName, string path)
        {
            SHA1CryptoServiceProvider sha = new SHA1CryptoServiceProvider();
            UnicodeEncoding encoding = new UnicodeEncoding();
            string hash = Convert.ToBase64String(sha.ComputeHash(encoding.GetBytes(path))).Replace('/', '_');

            if (String.IsNullOrEmpty(userName))
                return HttpContext.Current.Server.MapPath(String.Format("~/App_Data/Personalization_Data/{0}_Personalization.txt", hash));
            else
            {
                // NOTE: Consider validating the user name here to prevent
                // malicious user names such as "../Foo" from targeting
                // directories other than ~/App_Data/Personalization_Data

                return HttpContext.Current.Server.MapPath(String.Format("~/App_Data/Personalization_Data/{0}_{1}_Personalization.txt",
                                    userName.Replace('\\', '_'), hash));
            }
        }
    }
}

 Now I don't know what to do next, how to tie WebPart.aspx page with TextFilePersonalizationProvider.aspx.cs and with the rest of my web application. Is there a sample code for things like that? Thank you.

[RESOLVED] Web parts problem with menu

Hello,

I have some problems with Web Parts. My problem is following:

1. I add UserControl to Project (WebForms Applicataion - empty template). This user control have Calendar

2. I add to my Default Page code to displaying webpart which is made from user control:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication6.WebForm1" %>

<%@ Register src="WebUserControl1.ascx" tagname="WebUserControl1" tagprefix="uc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:WebPartManager ID="WebPartManager1" runat="server">
        </asp:WebPartManager>
        <asp:CatalogZone ID="CatalogZone1" runat="server">
        </asp:CatalogZone>
        <asp:WebPartZone ID="WebPartZone1" runat="server">
            <ZoneTemplate>
                <uc1:WebUserControl1 ID="WebUserControl11" runat="server" />
            </ZoneTemplate>
        </asp:WebPartZone>
    </div>
    </form>
</body>
</html>

When I run application I see: http://img94.imageshack.us/i/62791380.png/

There is one probblem: I don't have possibility to see menu button which in many courses about WebParts is in right upper conrner of the Web Part component.

I don't know what I do wrong.

 

Thanks for any help,

Patrick

Turn the webparts into design display mode. Try this code at Page Load event:

WebPartManager1.DisplayMode = WebPartManager.DesignDisplayMode;

Hi,

According to your description ,as far as I know ASP.NET Web Parts framework works with the Membership framework as well as the Forms or Windows authentication modes. The problem is that, if you do not want to use any authentication mode, you can not use Web Parts.

The client user, who will able to change the web site's design with Web Parts, should be authenticated. If not authenticated, the ASP.NET Web Parts framework can not  save users' design settings with data providers and for that reason can not allow even to switch design modes.

patryk88

There is one probblem: I don't have possibility to see menu button which in many courses about WebParts is in right upper conrner of the Web Part component.

I don't know what I do wrong.

For my experience ,this issue can occur if you give the Anonymous user access in the <authorization> section of the Web.config file.

I would like to suggest you to check the link below for the article which describes how to disable anonymous authentication in IIS.

http://www.iis.net/ConfigReference/system.webServer/security/authentication/anonymousAuthentication

Please check the link below for the sample that includes how to enable users to edit pages and change layout.

Creating a Web Parts Page

Hope it can help you.

Thank you for help! It's work!

 

Thanks again.

[RESOLVED] how to add multiple controls to Declarative Catalog Part by default

dear experts ,

i want to add control 1, control 2 etc.. by default in Declarative Catalog Part

and using following code


DeclarativeCatalogPart dp = (DeclarativeCatalogPart)CatalogZone1.FindControl("DeclarativeCatalogPart1");
      if (!DeclarativeCatalogPart1.HasControls())
      {
     

      Control x = LoadControl("UserControls/Provider.ascx");
      x.ID = "Provider.ascx";
     

      DeclarativeCatalogPart1.Controls.Add(x);
      x = LoadControl("UserControls/Consumer.ascx");
      x.ID = "Consumer.ascx";
     

      DeclarativeCatalogPart1.Controls.Add(x);
      



      }



but it only displays last item in it

any one guide me what mistake am i doing or what is the solution to my problem?

actually i want to give default 4-5 webparts options so that user could add it to page

any help would be appreciated.

Hi,

I think the problem is this:

Control Class is a reference type in C#, so if you want to create multiple instance of usercontrol, you need to use "new" use new to invoke the new default constructor.

Like:

DeclarativeCatalogPart dp = (DeclarativeCatalogPart)CatalogZone1.FindControl("DeclarativeCatalogPart1");
      if (!DeclarativeCatalogPart1.HasControls())
      {
     
      Control x = LoadControl("UserControls/Provider.ascx");
      x.ID = "Provider.ascx";
      DeclarativeCatalogPart1.Controls.Add(x);

      x = new Control();  //create a new instance
      x = LoadControl("UserControls/Consumer.ascx");
      x.ID = "Consumer.ascx";
     
      DeclarativeCatalogPart1.Controls.Add(x);
      
 
      }

More information about the value types and reference types you can check:

http://msdn.microsoft.com/en-us/library/s1ax56ch.aspx

http://www.albahari.com/valuevsreftypes.aspx

Hope this can help you.

Where in your code is this being called?  Why do you declare a DeclarativeCatalogPart dp and then never use it?  I can add a user control to DeclarativeCatalogPart1 but it always just gets dropped and replaced but whatever controls are statically declared in the aspx file.