User control setup in Kentico

Login to vote

Often times when adding custom controls to Kentico I will choose to use a plain user control over creating a new web part. The benefit of creating a web part is that you can allow the designer/content editor to set properties on your control from the design interface. If you do not require this ability it is simpler to add your user control using the "User control" web part located under the "General" section. All you need to do is set the virtual path to your user control (e.g. ~/Controls/MyControl.ascx). One thing you should add to any control/web part that executes code on load is a "StopProcessing" check. The CMS will sometimes ask your control to stop processing which is often the result of settings in the "Visibility" section of the web part's configuration. If the "StopProcessing" property is set to true the control will not be visible, but any code in a load event will still be executed. To handle this properly, add the following code to the beginning of the page load event in your user control.

protected void Page_Load(object sender, EventArgs e)
    if (Parent is CMS.PortalControls.CMSAbstractWebPart)
        if (((CMS.PortalControls.CMSAbstractWebPart)Parent).StopProcessing)

Since the control containing the user control is a web part, we can access the "StopProcessing" property through the parent property.

Posted by Ryan Williams on 4/11/2011 5:40:29 PM
No this does not solve that issue, but if you would like to post your code I will take a look.
4/19/2011 2:28:36 PM

Hi. I have been having trouble with postbacks in my webparts not firing events because kentico does something to the load event. I have been forced to put these webparts through the User control web part to get them to function properly. is this post a fix to that problem?
4/14/2011 3:56:22 AM