Thursday, April 24, 2008

A way to style elements on a page

There are several ways to add styles to elements on a page...
  • You can set a reference to a css file (from the style library) directly in the masterpage / page layout

  • You can specify a CSS file via the UI. Navigate to Site Settings > Site Master Page Settings -> Alternate CSS URL section

  • You don't have to use CSS files... you can also do it inline.

  • Another option is by using a Content Editor WebPart. In my option it is quick and dirty, but in some cases it might be useful.

How to style with a Content Editor WebPart?

  1. Set a CssClass for your control you want to style (or just a div with a class attribute)
    eg. myPanel.CssClass = "myPanel"

  2. Drag a Content Editor WebPart on the page

  3. Open the source editor and set the Css styles

When you are back in displayMode you will see that we have an ugly line (with default a webpart title). To hide this you can modify the webpart properties:

  • (appearance section) set the width attribute to "1px".
  • (appearance section) set Chrome Type to "None"
  • (appearance section) set Title to ""

Result: Our Content Editor WebPart is completely hidden and we have styled our page ;)

SharePoint Bug? SPListItem.Url

If you request the Url property of an SPListItem you'll retrieve an unexisting Url. Check out SPListItem.URL Funky Return Fiesta for further information. This property seems to work only for docitems. Weird!

Wednesday, April 23, 2008

How To: Make a nice looking contactform WebPart with AJAX

On my previous project I had to make some contactforms, to allow anonymous users to send an e-mail. I decided to make it as a webpart. I know, you can also do it with an application page (?), user controls with smartpart, etc... But a webpart has the advantage of properties and portability. Please, correct me if i'm wrong. I would really appreciate comments - other suggestions for making a form?

I made the contactform webpart without AJAX & Styling. Just a simple form with some simple validation handling. Everytime I build a customisation for a client, I always wondering if there wasn't a better (more beautiful, faster, other algorithm, etc) approach... In this case I started thinking about a nice looking contactform with AJAX validation and some nifty corners.

I gave it a try and my form looks like this:

After you have submitted the form:

How I did it...
  • I downloaded & installed the ASP.NET 2.0 AJAX Extensions 1.0
  • I modified my web.config
  • I placed a ASP.NET AJAX Script Manager into the masterpage
  • I downloaded the ASP.NET AJAX Control Toolkit

After these steps I created a webpart with the following code:

On Mike Ammerlaan's blog you'll read the following:

ASP.NET AJAX infrastructure is not compatible with output caching features. This output caching infrastructure is a featured component of managed content pages such as those supported by web content management features in Microsoft Office SharePoint Server. For this reason, many scenarios which involve output cached features may not be able to take advantage of components like UpdatePanel. However, you will be able to successfully use other ASP.NET AJAX features, such as the JavaScript library, combined with your output cached pages.

In my next post I'll show you a way to style the elements inside the webpart...

Thursday, April 3, 2008

Tip! SharePoint Search in combination with anonymous users

Have you already noticed that every time an unauthenticated user tries to search, a user prompt shows up? Well this is due to the fact that the OSSSearchResults.aspx has an inheritance reference to "Microsoft.SharePoint.WebControls.LayoutsPageBase". This inheritance isn't necessary to work properly. So... What you can do is just removing the whole line in the page directive "Inhertis=...." and save it. Don't forget to make a copy of the file!

Note - On MSDN you can read:

In general, use LayoutsPageBase as a base class for pages that should only be accessible to authenticated users with certain rights. For pages to which even
unauthenticated users should have access, use the parent class UnsecuredLayoutsPageBase.

I have tried to switch to this base class, but it didn't work for me. Anyone who did it?