In developing the Digital Signature Field for SharePoint I wanted to add a graphic to clearly display the current state of the signature. Is the signature old, new or invalid? A coloured tick can convey this intuitively while economising on size.
Controlling the rendering of a custom field’s value in most display modes is straight-forward through overrides to the SPField method GetFieldValueAsHtml(object) and the Render(…) methods of BaseFieldControl. When it came to rendering the value on the list display (i.e. AllItems.aspx) I found that SharePoint limited me to doing this through the RenderPattern element in the field type definition XML, with the caveat that any values, properties or calculations be limited to the CAML View Schema elements. The MSDN documentation on Patterns of Custom Field Rendering hints that a DisplayTemplate specification will let you gain control of the display mode, including the list display. After messing around for a while I felt quite confident that it didn’t include the list display mode.
Some Googling later, I found someone who had bent the rules a little to achieve complete control over display list value rendering. This IconSet custom calculated field project uses a custom RenderPattern to generate a script reference to a custom aspx page that dynamically renders some document.write(…) code that then renders HTML. Values necessary to identifying which item and field are supplied by the CAML and passed by URL parameters.
Cunning it is, although not exactly ideal. Every rendered value of your custom field must perform this additional page query to the server, thus lists with many values will take significantly longer to render. Unfortunately so far I’ve found no alternatives to gaining full control of display list rendering.
Note that this procedure is only required when you can’t render the correct output using the decision logic available in the CAML View Schema. In my case I chose not use the simple Text field type as the parent type instead of the popular MultiColumn field type.
My RenderPattern XML looks like this:
<RenderPattern Name="DisplayPattern">
<IfEqual>
<Expr1>
<Column />
</Expr1>
<Expr2 />
<Then />
<Else>
<HTML>
<![CDATA[<script language="javascript" src="../../_layouts/zmeng/]]>
<![CDATA[DigitalSignature/DigitalSignatureDisplay.aspx?ListId=]]>
<List />
<![CDATA[&ItemId=]]>
<ID />
<![CDATA[&FieldDisplayName=]]>
<Property Select="DisplayName"/>
<![CDATA["></script>]]>
</HTML>
</Else>
</IfEqual>
</RenderPattern>
The <IfEqual> tests whether the column has a value, and if not it avoids making a purposeless server request. Supplying the list GUID, item ID and list column display name, the receiving aspx page can query the value then render as necessary.
The receiving class is as below. Remember to set AutoEventWireup="true" in the connecting aspx file so the Page_Load method will be called.
public partial class DigitalSignatureDisplay : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string listId = Request.QueryString.Get("ListId").ToString(); string itemId = Request.QueryString.Get("ItemId").ToString(); string displayName = Request.QueryString.Get("FieldDisplayName").ToString(); Guid listGuid = new Guid(listId); int itemIndex = Int32.Parse(itemId); SPList spList = SPContext.Current.Web.Lists[listGuid]; SPListItem spListItem = spList.GetItemById(itemIndex); // Create some useful HTML output here // using the list item's value string output = "<b>le output</b>"; Page.Response.Write("document.write('" + output.Replace("'", @"\'") + "');"); Page.Response.Flush(); } }
The resultant effect of all that shown below.

Tags: C#, Custom Field, Digital Signature, WSS 3.0, XML
Hello,
I’m trying to reproduce your examples but I have a problem getting the SPContext. SPContext.Current is null all the time.
do you know where the problem could be ?
the aspx page I called is also under “_layouts” directory
Hi GillouX,
I can’t be sure unless I see your code in context, but ensure that you’re not trying to access
SPContextfrom anything but aPagecontrol that is requested by standard means. Are you attempting to query the _layouts directory directly per chance? Perhaps do a quick web search for ‘SPContext.Current null’ and see if anything jumps out. Otherwise, please post your code here and I’ll do my best.Best regards, Zac.