I am trying to set the value for href attribute of an anchor tag in one of my SharePoint Publishing Site layout pages. I need to set the value to the value stored in one of the columns in page's content type. I tried the following line, but I got an error message given below.

<a href='<%=<SharePointWebControls:FieldValue FieldName="SomeColumn" runat="server" /> %>'>Click here</a>

Error Message:

An error occurred during the processing of /_catalogs/masterpage/SomeLayoutPage.aspx. Code blocks are not allowed in this file.

Can anyone help me with this? I know that I can just use SharePointWebControls:UrlField control to get the link displayed on the page, but I'd like to have access to the value directly for other purposes too (like using the value for embeding YouTube video player etc.)

Thanks in advance!


You can only get the value out of page Content Type field using the C#:

string valueoffield = (string)SPContext.Current.ListItem["YourContentTypeFieldName"];
  • If you do this remember that anyone who has contribute rights to the masterpage gallery can put any code into the masterpages/page layouts – Per Jakobsen May 30 '12 at 11:33
  • Remember, it's not elegant of approaches. – Falak Mahmood May 30 '12 at 17:18
  • Thanks for the response Falak and Per! But is there another way to get just the value out of the page content type field? Through some other SharePoint webcontrol, perhaps? – Girish May 31 '12 at 14:41
  • No, you can't do it using SharePoint web controls. The only option is to use code behind. – Falak Mahmood Jun 19 '12 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.