Portal Engine Questions on portal engine and web parts.
Version 7.x > Portal Engine > Checking if a custom web part will be visible View modes: 
User avatar
Certified Developer v7
Certified  Developer v7
Erik - 3/22/2013 6:08:18 PM
   
Checking if a custom web part will be visible
I have a web part inside of a zone marked "Hide on sub pages".

When I'm on a sub page, I don't want that web part's logic to run.

Inside the OnPreRender, I looked at the web part's "Visible" property, and all of it's parents, and the value ways always "True".

How can I check if a custom web part is going to be visible so I can avoid running its logic?

Thanks,
Erik

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 3/22/2013 7:45:38 PM
   
RE:Checking if a custom web part will be visible
Technically, if its hidden on sub pages, the code in the web part won't even run. But you can check the this.Visible property of your web part if you need.

User avatar
Kentico Support
Kentico Support
kentico_radekm - 3/23/2013 5:58:42 AM
   
RE:Checking if a custom web part will be visible
Hello.
When I'm on a sub page, I don't want that web part's logic to run.

Does not it help if you simply set "Hide on sub-pages" property in web part's configuration dialog?

Best Regards,
Radek Macalik

User avatar
Certified Developer v7
Certified  Developer v7
Erik - 3/24/2013 11:23:09 PM
   
RE:Checking if a custom web part will be visible
All the web part user control's lifecycle functions continue to get hit. I can verify this debugging with breakpoints or with logging.

And, as I mentioned, the Visibility property is always true, despite this not being the case.

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 3/25/2013 8:47:56 AM
   
RE:Checking if a custom web part will be visible
Then check this.HideOnSubPages property if Visible isn't working.

User avatar
Certified Developer v7
Certified  Developer v7
Erik - 3/25/2013 10:05:41 AM
   
RE:Checking if a custom web part will be visible
That value is also incorrectly true when it shouldn't be.

Also, how would I then detect if I'm on a sub page to compare that value?

User avatar
Certified Developer v7
Certified  Developer v7
Erik - 3/25/2013 10:32:45 AM
   
RE:Checking if a custom web part will be visible
Well, here's the answer I was looking for:

- "Visible" and "IsVisible" properties just check that the checkbox is checked on the web part properties, and don't take in consideration if the web part is hidden on sub pages or for certain document types.

- There is a bug in "HideInCurrentPage" and "HideOnSubPages" that doesn't take into account a web part's parent zone.

This code works for me:
if (!this.HideOnCurrentPage && !this.ParentZone.HideOnCurrentPage)
{
// execute custom web part code here
}

I still don't think I should have to do this check.

User avatar
Kentico Support
Kentico Support
kentico_radekm - 4/3/2013 1:15:14 AM
   
RE:Checking if a custom web part will be visible
Hello.

If the web part is not visible from some reason and its code should not be executed is being checked in the SetupControl method. There is a condition "if (!StopProcessing)" which ensured that. If you placed your code into some event which is fired before this SetupControl method, it is executed then.

If you face this problem under some special scenario, send me an e-mail to support@kentico.com with exact description of your scenario, so we can check it. Thank you.

Best Regards,
Radek Macalik