asp tutorials, asp.net tutorials, sample code, and Microsoft news from 15Seconds
Data Access  |   Troubleshooting  |   Security  |   Performance  |   ADSI  |   Upload  |   Email  |   Control Building  |   Component Building  |   Forms  |   XML  |   Web Services  |   ASP.NET  |   .NET Features  |   .NET 2.0  |   App Development  |   App Architecture  |   IIS  |   Wireless
 
Pioneering Active Server
 Power Search








Active News
15 Seconds Weekly Newsletter
• Complete Coverage
• Site Updates
• Upcoming Features

More Free Newsletters
Reference
News
Articles
Archive
Writers
Code Samples
Components
Tools
FAQ
Feedback
Books
Links
DL Archives
Community
Messageboard
List Servers
Mailing List
WebHosts
Consultants
Tech Jobs
15 Seconds
Home
Site Map
Press
Legal
Privacy Policy
internet.commerce














internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

HardwareCentral
Compare products, prices, and stores at Hardware Central!

Customizing SharePoint Web Parts with Custom Properties -- Cont'd
By Gayan Peiris


  • email this article to a colleague
  • suggest an article

    Code Example

    In the CustomizedWebPart code sample I am looking at customizing the behavior and functionality of Web Parts using custom properties. The Web Part is developed using the Visual Studio .NET environment. This sample contains a DataGrid control which displays customer information. Using our custom properties, the user will be able to customize the following information:

    1. Select to view chosen customer record in DataGrid in separate detail pane by checking a check box in property pane.
    2. Selecting a company name from an enum class that will make company names available in the property pane.
    3. Adding an accountant name from a text box in the property pane.

    It is important to understand how to develop custom Web Parts before we start any coding. Please refer to my previous article "Developing Web Parts for SharePoint 2003 in VS.NET" for more information regarding developing Web Parts. (http://www.devx.com/dotnet/Article/17518)

    How to add a check box to the property pane

    First let's look at adding a check box to the property pane.

    ///<summary>

                /// This property will determine, wether to display the selected customer

                /// information in a detail pane in label controls.

                /// This will be available in a check box.

                ///</summary>

                [Browsable(true), //Display the property in property pane

          Category("Customer Details"), //Create a Customer Details category in

    property pane

                DefaultValue(false), //Assign a default value

                WebPartStorage(Storage.Personal),//Make available in both personal and

    shared mode

                FriendlyName("Display Details"), //The caption display in property pane

                Description("Displaying Customer Details")]//The tool tip

                publicbool DisplayCustomerDetails

                {

                      get

                      {

                            return m_blnDispalyDetails;

                      }

     

                      set

                      {

                            m_blnDispalyDetails = value;

                      }

                }

    Figure 6: Custom property code that will create a check box in the property pane

    The above code will create a Category named "Customer Details" in the property pane. This will help organize the information in a logical manner. Whenever any customer customization needs to be done, we will be able to go straight to the "Customer Details" category.

    Figure 7: The "Customer Details" category added to the property pane with a check box.

    When above check box in not selected, the customer DataGrid will display as follows:

    Figure 8: Default look of Customer Web Part

    When user selects the "Display Details" check box from the property pane, it will render as follows:

    TIP: To access the property pane, select the Edit mode of the Web Part. Then click the down arrow located at top right hand corner of the Web Part. Select "Modify Shared web part" (or personnel depend on witch mode the Web Part is running). This will open the property pane and then expand the "Customer Details" category. At the end, click Apply and Ok buttons.

    Figure 9: Customized Web Part with additional customer details

    How to add a drop down list to the property pane

    Secondly, let's make use of an enum structure which contains company names (as displayed below).

    ///<summary>

                /// Holds the company names

                ///</summary>

                publicenum CompanyName : int

                {

                            TaxOffice  = 0, //This will display customers as Tax Office Customers

                            PostOffice = 1, //This will display customers as Post Office Customers

                            Bank = 2, //This will display customers as Bank Customers

                            Telephone = 3 //This will display customers as Telephone Customers

                }

    Figure 10: Enum class that hold the company names

    I expose this enum class as a Web Part custom property as display below,

    ///<summary>

                            /// This property will determine the name of the company.

                            /// The names of the companies are stored in an enum collection.

                            /// This will be available in a drop down list.

                            ///</summary>

                            [Browsable(true),//Display the property in property pane

                            Category("Customer Details"),//Create a Customer Details category in

    property pane

                            DefaultValue(CompanyName.Bank),//Assign a default value

                            WebPartStorage(Storage.Personal),//Make available in both personal and

    shared mode

                            FriendlyName("Company name"),//The caption display in property pane

                            Description("Select the office")]//The tool tip

                            public CompanyName DisplayCompanyName

                            {

                                        get

                                        {

                                                    return m_enmSelectedCompany;

                                        }

     

                                        set

                                        {

                                                    m_enmSelectedCompany = value;

                                        }

                            }

    Figure 11: Custom property with an enum class

    This custom property will display in property pane as below

    Figure 12: "Company Name" custom property in a drop down list

    The user can select any company name they prefer and this information will display in the Web Part as shown below:

    Figure 13: Displaying selected "Bank" company name from property pane.

    How to add a text box to the property pane

    Finally, let's have a look at adding a text box to property pane. The following code will allow the user to type a string value in a text box. Then I will use this string value as the accountant's name for the customers displayed.

    ///<summary>

                /// This property will allow to enter a string value to a text box.

                ///</summary>

                [Browsable(true),//Display the property in property pane

                Category("Customer Details"),//Create a Customer Details category in

    property pane

                DefaultValue("John Smith"),//Assign a default value

                WebPartStorage(Storage.Personal),//Make available in both personal and

    shared mode

                FriendlyName("Accountant name"),//The caption display in property

    pane

                Description("Accountant name")]//The tool tip

                publicstring AccountantName

                {

                      get

                      {

                            return m_strAccountantName;

                      }

     

                      set

                      {

                            m_strAccountantName = value;

                      }

                }

    Figure 14: Custom property with text box

    This custom property will display in the property pane as follow,

    Figure 15: Custom property as a text box to input Accountant name

    The user can input any name they like and this will show in the Web Part as displayed below:

    Figure 16: Displaying the accountant's name from property pane.

    Conclusion

    The custom properties provide flexibility in customizing a Web Part according to the organization's or user's needs. We will be able to do all above customization code through the Visual Studio .NET environment. This will provide us with all the advantages and functionality available from the VS.NET environment such as debugging.

    There is more to Web Parts. Another technique of introducing even more custom functionality and behavior to a Web Part is the implementation of Tool Parts. I will discuss how to create Tool Parts to customize a Web Part in the near future.

    About the Author

    Gayan Peiris is a Senior Consultant for Unique World Pty Ltd (www.uniqueworld.net) in Canberra, Australia. He is a MCAD with MCP, Bcom and MIT certifications. Gayan has designed and developed Microsoft Web and Windows solutions since 1999. His expertise lies in developing scalable, high-performance web and windows solutions. His core skills are ADO.NET, ASP.NET, C #, VB.NET, Web Services, XML, SharePoint Portals, DNA and SQL Server. He can be reached at www.gayanpeiris.com.

    << Introduction

    Rate This Article

  • Other Articles
    Apr 27, 2004 - Develop and Customize Web Parts with Custom Tool Parts
    Tool Parts provide an interface for Web Part properties well beyond the capabilities of the default property pane. In this article Gayan Peiris shows how to customize Web Parts with custom Tool Parts.
    [Read This Article]  [Top]
    Apr 7, 2004 - Reusable Components in ASP.NET 2.0, Object Binding and Precompilation
    This article demonstrates how to create a reusable component in ASP.NET 2.0 and then consume it from an ASP.NET page. Also learn how the ObjectDataSource control can be used to directly bind the output of an object to the controls in an ASP.NET page and how precompilation can be used to increase the performance of the Web application and catch compilation errors.
    [Read This Article]  [Top]
    Mar 31, 2004 - Build a Managed BHO and Plug into the Browser
    Browser Helper Objects (BHOs) are COM components that communicate with Internet Explorer to enrich the browsing experience. Michele Leroux Bustamante returns to the world of COM to show you how to build a managed BHO with the help of the .NET Framework's COM interoperability features.
    [Read This Article]  [Top]
    Feb 18, 2004 - Customizing SharePoint Web Parts with Custom Properties
    In addition to creating custom Web Parts for SharePoint Portal Server, developers can actually create their own custom properties to further enhance Web Part appearance and behavior. Gayan Peiris explains the process and provides all the necessary code.
    [Read This Article]  [Top]
    Sep 26, 2003 - Accessing Shared Resources Using ASP.NET
    Accessing shared resources is a challenge for many ASP.NET developers. Tony Arslan explains how a simple serviced component can solve this infamous problem.
    [Read This Article]  [Top]
    Oct 2, 2002 - Function Pointers and COM
    Using callbacks and function pointers in VB can be risky and complicated. Ben Garcia explains his work-around for the function pointer issue he encountered while creating the VB version of his SNMP component.
    [Read This Article]  [Top]
    Sep 4, 2002 - Creating an SNMP Component - Part 2
    In part two of this intriguing article series, Ben Garcia shows how to build an updated and improved SNMP component in VC++ AND VB, and he briefly explains why limitations in VB make VC++ a better language for developing this type of application.
    [Read This Article]  [Top]
    Jul 23, 2002 - Creating an SNMP Component
    Ben Garcia sheds some light on the Simple Network Management Protocol (SNMP). First he provides a history of SNMP, then he dives right into its architecture. Finally, he shows how to build a COM component that communicates with SNMP-enabled devices.
    [Read This Article]  [Top]
    Jun 26, 2002 - Accessing Caller ID from the Web - Part 1
    Paul Apostolos begins his series on using Web services and the MSComm32.OCX component to access caller id information from a Web page. In part 1, learn how to write the Visual Basic program that runs on the server and updates a database with incoming callers.
    [Read This Article]  [Top]
    Nov 20, 2001 - Creating a Server Component with VB - Redesigned - Part 2
    Doug Dean explains different methods of retrieving and manipulating data from a database in a VB DLL so that it is ready to be rendered in a browser.
    [Read This Article]  [Top]
    Mailing List
    Want to receive email when the next article is published? Just Click Here to sign up.

    Support the Active Server Industry



    JupiterOnlineMedia

    internet.comearthweb.comDevx.commediabistro.comGraphics.com

    Search:

    Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

    Jupitermedia Corporate Info


    Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

    Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

    Solutions
    Whitepapers and eBooks
    Microsoft Article: HyperV-The Killer Feature in WinServer ‘08
    Avaya Article: How to Feed Data into the Avaya Event Processor
    Microsoft Article: Install What You Need with Win Server ‘08
    HP eBook: Putting the Green into IT
    Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
    Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
    Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
    Avaya Article: Setting Up a SIP A/S Development Environment
    IBM Article: How Cool Is Your Data Center?
    Microsoft Article: Managing Virtual Machines with Microsoft System Center
    HP eBook: Storage Networking , Part 1
    Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
    MORE WHITEPAPERS, EBOOKS, AND ARTICLES
    Webcasts
    Intel Video: Are Multi-core Processors Here to Stay?
    On-Demand Webcast: Five Virtualization Trends to Watch
    HP Video: Page Cost Calculator
    Intel Video: APIs for Parallel Programming
    HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
    Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
    MORE WEBCASTS, PODCASTS, AND VIDEOS
    Downloads and eKits
    Sun Download: Solaris 8 Migration Assistant
    Sybase Download: SQL Anywhere Developer Edition
    Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
    Red Gate Download: SQL Compare Pro 6
    Iron Speed Designer Application Generator
    MORE DOWNLOADS, EKITS, AND FREE TRIALS
    Tutorials and Demos
    How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
    eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
    IBM Article: Collaborating in the High-Performance Workplace
    HP Demo: StorageWorks EVA4400
    Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
    Microsoft How-to Article: Get Going with Silverlight and Windows Live
    MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES