SharePoint create custom list forms with Visual Studio Part 3

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 1: Setting up a solution with a list definition, a list instance and deploy it.

Part 2: Creating a custom list form and connect it with the list definition.

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:

customListForm15

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.

customListForm16

After that a window will appear in which you can add a safe control entry.

customListForm17

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:

customListForm18

And of course of your code behind:

customListForm19

After that, your form should work like a charm again:

customListForm21

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”>

<PageParserPaths>

<PageParserPath VirtualPath=”/*” CompilationMode=”Always” AllowServerSideScript=”true” IncludeSubFolders=”true” />

</PageParserPaths>

</SafeMode>

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.

About Karsten Schneider 312 Articles
Consultant for Microsoft 365 Applications with a strong focus in Teams, SharePoint Online, OneDrive for Business as well as PowerPlatform with PowerApps, Flow and PowerBI. I provide Workshops for Governance & Security in Office 365 and Development of Solutions in the area of Collaboration and Teamwork based on Microsoft 365 and Azure Cloud Solutions. In his free time he tries to collect tipps and worthy experience in this blog.

4 Comments

  1. Dear Karsten Pohnke
    I would like to say Thank you for this, this is what I was looking for, and was resolving the issue for 1 week, until I got to your post. Safe Control namespace – was the deal breaker, none other article mentioned it.
    Thank you so so much!

1 Trackback / Pingback

  1. SharePoint create custom list forms with Visual Studio Part 2 | devzsharepoint

Leave a Reply to Paul Cancel reply

Your email address will not be published.


*