Showing posts with label Sitecore. Show all posts
Showing posts with label Sitecore. Show all posts

Tuesday, March 15, 2011

Sitecore and FieldRenderer

I get work with Sitecore quite a bit, and even though I do like the product itself, my biggest gripe is that the online documentation is sparse and not easily searchable. In particular, I could not find the documentation for FieldRenderer format parameters anywhere. These are extremely useful for formatting Date and Image fields.

First include WebControls namespace to use FieldRenderer:
using Sitecore.Web.UI.WebControls;

Next, use the following overload for the Render method:
FieldRenderer.Render(Item item, string fieldName, string parameters);

As far as the parameters argument goes, this where I had to dig endlessly to figure out the right string every time I use the functionality. Here is the info I was able to come up with, which will hopefully save you some time:

1. Date Formatting, add format= and then formatting string you want to use
FieldRenderer.Render(item, "Date", "format=MM/dd/yyyy")

2. Images - one thing to note, URL format is used to combine parameters together.
FieldRenderer.Render(item, "Date", "w=500&h=700&as=1")

For images the list of options is significantly larger:

w: - Width
h: - Height
mw: - Max Width
mh: - Max Height
la: - Language
vs: - Version
db: - Database
bc: - Background Color
as: - Allow Stretch
sc: - Scale (.33 = 33%)

Tuesday, February 22, 2011

Sitecore 6 and IIS6 form postback causes layout redirect

Recently, wile working on a legacy website build on Sitecore 6.0 and IIS6, I ran into a problem with form posts / post back. On postback, instead of seeing the actual page, I was seeing the layout page being posted to. This threw a 404 error.

After a bunch of research, it turned out that the issue was a missing App_Browsers folder. That folder contains Form.browser file, essential for the postback to work properly.

Thanks to Neil Pullinger's blog entry, I was able to get postbacks working correctly.