This is the third part of my post serie. In this post serie i would like to share my experience with custom list forms in SharePoint 2010 and 2013. Normally you start a visual studio solution with a list definition and a list instance. These posts will show you step by step to add a custom list form which will work fine even with code behind.
Part 3: Necessary settings for custom listform in Visual Studio
In post 2 we created our custom list form and it worked. It was based on the posts i mentioned. But there was something what throws an exception that was not mentioned anywhere along with custom forms.
Let’s make a test. After you followed part 1 und part 2 and you successfully deployed your custom list with a custom display form, you now should make any modifications to the masterpage. Anything, it does not matter what. I did it and the result is the following exception:
Ok, what? Base type not safe?
I checked it, if you now reset your masterpage to web site definition, the error dissappears.
Tip: Do not modify your masterpage or read on!
The error happens because your custom form and from what it inherit is not added to the web.config as safecontrol. So how to put it into the safecontrol entries, i will show in the next steps.
In Visual Studio select the list definition or the parent folder of your custom list form and click in the property pane on the button (…) of Safe Control Entries.
After that a window will appear in which you can add a safe control entry.
Ok, after you added the control entry, you should copy the namespace from screen above. You have to add it to your custom displayform.aspx and displayform.aspx.cs.
Well, customize the inherits of your aspx page:
And of course of your code behind:
After that, your form should work like a charm again:
That’s it, what i missed and had to figure out. I luckily found the hint in this post.
Now we are done. Maybe i will write a another post about using the fields. Oh i forgot. If you are using code behind in your custom list form, and maybe there is a gridview or another control which uses an event handler, you might get one of those errors:
“The event handler ‘OnClick’ is not allowed in this page”
“The event hanler ‘OnRowCommand’ is not allowed in this page”
Then do not be desperated. The solution is to modify the web.config of your application. Simply add the red marked text into your. web.config like this post suggested:
<SafeMode MaxControls=”200″ CallStack=”true” DirectFileDependencies=”10″ TotalFileDependencies=”50″ AllowPageLevelTrace=”false”>
<PageParserPath VirtualPath=”/*” CompilationMode=”Always” AllowServerSideScript=”true” IncludeSubFolders=”true” />
After that the error will dissapear. Hope you enjoyed the three parts.
..:: I LIKE SHAREPOINT ::..The article or information provided here represents completely my own personal view & thought. It is recommended to test the content or scripts of the site in the lab, before making use in the production environment & use it completely at your own risk. The articles, scripts, suggestions or tricks published on the site are provided AS-IS with no warranties or guarantees and confers no rights.