Why is the full relative path to CodeBehind a requirement?

Zach L asked on January 11, 2017 15:51

In the Kentico documentation on the topic of creating custom web parts it is always mentioned that the full relative path of the code behind needs to be specified, but for whatever reason visual studio did not like it when I did specify the full relative path so I didn't bother with it and it seems to be working just fine. So why is this a requirement ?

This is what I am referring to:

"The Control declaration in the markup of the web part's user control file must contain the full relative path to the code behind file in the CodeFile attribute (CodeBehind attribute on web application installations)"

Creating new web parts

Correct Answer

Brenden Kehren answered on January 11, 2017 16:09

Because when you create a webpart layout, it's needed to build the virtual layout dynamically. The full relative path to the code file should look something like this:

CodeFile="~/CMSWebParts/MyWebparts/CustomWebpart.ascx.cs"

Also make sure you have the proper Inherits attribute set in the <Control> declaration. I'm guessing something isn't setup properly within that user control for Visual Studio to not like it.

1 votesVote for this answer Unmark Correct answer

Recent Answers


Zach L answered on January 11, 2017 16:28

Thanks! That is exactly what I have just found out, the web part was working fine with a default layout but as soon as I changed it to something else it would stop working.

My issue was how I named my folder in the VS solution, "Custom Web Parts"

In the control file "~/CMSWebParts/Custom_Web_Parts/WebUserControl.ascx.cs" was not working. Once I removed the spaces from the folder name and the path it worked fine.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.