Aidan Garnish
MOSS 2007 and other Microsoft technologies

Web part custom property - dropdown list

December 19, 2007 09:40 by aidan

It isn't immediately obvious how to include a drop down list as a custom property on a web part. To do this you simply use an enum.

Eg.

//create enum

public enum ProductByEnum

{Type = 0,

Brand,

Chemistry};

//create get/set for the property

protected ProductByEnum productsBy;

[Personalizable(PersonalizationScope.User),WebBrowsable, WebDisplayName("Products By"),WebDescription("Use this property to change web part grouping")]public ProductByEnum ProductsBy

{

get { return productsBy; }

set { productsBy = value; }

}

A dropdown list will now appear in the miscellaneous section of your web part custom properties containing the enum values.


Currently rated 3.7 by 3 people

  • Currently 3.666667/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Creating XHTML compliant ASP.Net server controls

December 12, 2007 09:38 by aidan

ASP.Net is great but many of the controls use table tags when they render. I am currently in the process of developing some Internet sites using MOSS 2007 which need to meet accessibility guidelines so these controls, in their out of the box state, are no use to me. We have tried applying the CSS adapters that get rid of the tables but this also had the effect of removing tables from the site settings screens making them difficult to use.

The solution we are going for is to create new controls that inherit from the base control. The new control then overrides the render event to remove the non-compliant tags and replaces them with compliant ones.

We are also using this method to add script to the master pages which removes table tags from web part zones etc.

DISCLAIMER - I have created a non-tabular control for the SPGridView. You could argue that the SPGridView presents tabular data so does not need any changes to the rendered HTML, you would probably be right but this example shows what can be done. :-)

using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Web.UI;
using System.Text.RegularExpressions;
using System.IO;

namespace XHTMLCompliantMOSSControls
{
    public class CompliantSPGridView : SPGridView
    {
        protected override void RenderContents(HtmlTextWriter output)
        {
            //get the rendered HTML
            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);
            HtmlTextWriter hw = new HtmlTextWriter(sw);

            base.RenderContents(hw);
 
            //remove tables
            string str = sb.ToString();
          
            str = Regex.Replace(str, "<table[^>]*>", "<div class=\"mainSPGridView\">");
            str = Regex.Replace(str, "<tr>", "<div class=\"normalSPGridView\">");
            str = Regex.Replace(str, "<tr class=\"ms-alternating\">", "<div class=\"alternatingSPGridView\">");
            str = Regex.Replace(str, "</tr>", "</div>");
            str = Regex.Replace(str, "<td[^>]*>", "<div class=\"itemSPGridView\">");
            str = Regex.Replace(str, "</td>", "</div>");
            str = Regex.Replace(str, "<tr class=\"ms-viewheadertr\">", "<div class=\"headerSPGridView\">");
            str = Regex.Replace(str, "<th class=\"ms-vh2-nofilter ms-vh2-gridview\" scope=\"col\">", "<div class=\"itemSPGridView\">");
            str = Regex.Replace(str, "</th>", "</div>");
          
            output.Write(str);
        }
    }
}

If you then apply a bit of CSS using the classes that have been added it is possible to get it looking just like the tabular SPGridView.

This approach could be used with any server control to make it compliant with XHTML.


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

MOSS 2007 end user training is released

December 10, 2007 22:07 by aidan

Microsoft have released end user training materials for MOSS 2007. This can be downloaded as a stand alone version that can be run from the desktop or as a version that can be installed and distributed as a set of SharePoint sites. The advantage of installing it to SharePoint is that as a trainer you can direct people towards content and get reports on who has successfully completed which modules.

Download the training here


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Excellent post about making SharePoint xhtml compliant

December 10, 2007 15:02 by aidan
For anyone using the web content management components of MOSS 2007 to produce Internet sites this is essential reading. SharePoint uses a lot of ASP.Net controls which render using tables and non compliant html. To get rid of this there are a few things you can do which are explained in this blog post http://zac.provoke.co.nz/archive/2007/04/19/guide-to-making-sharepoint-xhtml-compliant.aspx

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

An efficient way to set web control values

December 10, 2007 11:11 by aidan

Rather than setting the widths of label and textbox controls individually like this:

oLabel1.Width=150;

oLabel2.Width=150;

oLabel3.Width=150;

It is much more efficient to add the controls to the controls collection and use:

foreach(Control oControl in this.Controls)
{
     if (oControl.GetType().ToString() == "System.Web.UI.WebControls.Label")
     {
       Label oLabel = (Label)oControl;
       oLabel.Width = 120;
     }
}

This then allows you to change the widths of all your labels within the page or web part in one place. This approach can also be taken with other controls like text boxes and drop downs or could be used to set other properties such as font or color.

Or you could just use CSS.  Smile


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:
Categories: ASP.Net
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

Creating an advanced search box and results web part

December 4, 2007 09:08 by aidan

Useful links for creating an advanced search web part:

http://www.tqcblog.com/archive/2007/10/25/creating-a-custom-advanced-search-box-in-moss-2007.aspx

http://dattard.blogspot.com/2007/11/sharepoint-2007-creating-custom.html

http://dattard.blogspot.com/2007/11/creating-custom-advanced-search-webpart.html


Currently rated 1.0 by 1 people

  • Currently 1/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:
Categories: MOSS 2007
Actions: E-mail | Permalink | Comments (2) | Comment RSSRSS comment feed

Good news for web accessibility

December 3, 2007 21:55 by aidan
The Accessibility Kit for SharePoint is now available. This includes master pages, css, control adapters, reusable content and a tool to implement sizable text. To download the kit go to http://www.codeplex.com/aks

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

SP1 is coming!

December 3, 2007 21:50 by aidan
SP1 for WSS 3.0 and MOSS 2007 is on it's way. Includes 60+ hotfixes, AJAX support for web parts and new STSAdm commands see http://blogs.msdn.com/sharepoint/archive/2007/11/29/preview-into-wss-3-0-sp1-and-sharepoint-server-2007-sp1.aspx for more detail...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:
Categories: MOSS 2007
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

Setting custom properties on web parts

December 3, 2007 10:49 by aidan

When creating web parts it is often useful to allow users to supply some additional parameters to the web part. This can be done by adding custom attributes which can then be set by the user and used in your code.

To do this use the following syntax:

   [Personalizable(PersonalizationScope.User),
         WebBrowsable, WebDisplayName("Products List"),
         WebDescription("Use this property to change list used to retrive products from")]
        public string ProductList
        {
            get { return strProductsList; }
            set { strProductsList = value; }
        }

In this case, rather than hard coding the name of the products list, the user is able to specify which list to use.


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5