Web Part Layout Page markup

Charles Matvchuk asked on September 15, 2016 06:17

I need to use the Sign out button web part with a different layout. I have created my layout, and understand on how to select a different layout when I add the web part to a zone. The challenge I am having is that I need to add the web part to the page in the markup and I cannot figure out how to specify the layout.

<%@ Register src="~/CMSWebParts/Membership/Logon/SignOutButton.ascx" tagname="SignOutButton" tagprefix="uc1" %>

<uc1:SignOutButton ID="SignOutButton1" runat="server" SignOutText="Logout" ShowAsLink="true" ShowOnlyWhenAuthenticated="true" RedirectToUrl="~/Home" />

Where would I define which layout I want to use? I figured it would be a property but I cannot find anything in the documentation and I am stumped.

The second part of my dilemma is when I create an inherited web part, how do I add it directly to the page markup, as I have done with the example above? I don't find any documentation regarding this.

Any help with both of these challenges would greatly be appreciated.

Recent Answers


Roman Hutnyk answered on September 15, 2016 17:29

Regarding second question:

In your example your adding user control (not an actual web part), that web cart is created based on. As long as inherited web part is based on the same code files (https://docs.kentico.com/display/K9/Creating+inherited+web+parts) in fact it is same user control, so you'll add it like the first one.

There might be some options depending on what is the difference between original and inherited web part.

1 votesVote for this answer Mark as a Correct answer

Charles Matvchuk answered on September 15, 2016 18:11

Roman,

I do understand that it is the same web part when it is inherited. I have read the documentation. But to add it as a user control, there is no mention or documentation on how to do that. If you have an example that would be great. I add user controls all the time, but I have no idea how to add the inherited user control.

0 votesVote for this answer Mark as a Correct answer

Stephen Rushing answered on September 15, 2016 20:03 (last edited on September 15, 2016 20:25)

The Web Part's main ascx file is, in effect, the default layout, which references the codebehind. Web Part Layouts are essentially the same thing. I have not done what you're trying to do, specifically, but I'm thinking you'll need to enable storage of virtual objects and reference the layout ascx file that's created for the layout you want to use.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on September 15, 2016 22:17

Charles,

I've done this 2 ways in the past:

  • Cloned the webpart and modified the default layout. This will then become the default layout no matter where you place it. You can then create additional layouts and select those as needed.
  • Created a widget based on the webpart and in the widget you can tell it what layout to use. This requires you to have editor zones on your site though and if you don't want users to edit that, then you'll have to make sure you have permissions set properly.
0 votesVote for this answer Mark as a Correct answer

Charles Matvchuk answered on September 15, 2016 22:46

Brenden,

Thanks for the input. I do, do it both those ways right now. I was looking for a solutions by which I could utilize a complete stock portal solution without cloning and creating any additional .ascx files. I am seeing that it really can't be accomplish without doing so.

0 votesVote for this answer Mark as a Correct answer

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