Strange Layout Behavior when adding inline code to site layout.Master

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
11/19/2010 2:43:45 PM
Gravatar
Total Posts 18

Strange Layout Behavior when adding inline code to site layout.Master

I'm using RadMenu for the menu on my website and I'm loading the data for the menu using XML files. I would like to be able to display a different XML menu file based on the user's permissions. Typically how I would do this is to create a Page_Load event on the master page, check the current user's role and then load the corresponding XML file into the RadMenu.

I figured out that I can't do this in a code behind file with MojoPortal, so I created an inline script on the layout.Master page for my skin and specified the correct code for the Page_Load event.

This actually works fine...the menu is loaded with the proper options, however, for some reason, adding this throws off the width of my wrapcenter <div> so it's really small and doesn't fill the full specified 980px. Removing the inline script returns the layout to the proper width.

I'm having a really hard time understanding why the addition of the inline script would do this...seems like the two areas should be completely unrelated.

My other option is to specify the menu items declaratively in the RadMenu control which also works fine, I just don't know how I can throw code within this to turn off certain menu items based on the user's role.

If anyone has had experience with the layout problem when using inline code, or has an idea on how I can use MojoPortal role permissions in my RadMenu control to turn on/off certain items, I would appreciate the assistance. Thanks.

11/22/2010 2:37:52 PM
Gravatar
Total Posts 245
mojoPortal Community Expert

Re: Strange Layout Behavior when adding inline code to site layout.Master

Here's a code snippet using Radmenu loading the xml file in code behind.

 protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                RadMenu1.LoadContentFile("~/Menu/Data/OfficeMenu.xml");
            }
        }

I use an xml file for my RadTabStrip.

BTW if you are using Telerik in mojoPortal, you just have to buy this mojoRadGlue Editor Provider code from Joe for $9.00.
It works Great!

Hope this helps.

Arivixe.com

Rick

11/22/2010 2:51:09 PM
Gravatar
Total Posts 18

Re: Strange Layout Behavior when adding inline code to site layout.Master

Hi Rick,

Thanks for the reply. That is pretty much the same code I was using. Can I ask you which code-behind file you are adding it to where it actually works? Did you create a layout.Master.cs file for the master page in ~/App_MasterPages or did you add it to the master page for your skin under ~/Data/Sites/#/skins/skinname? What does the "Inherits" tag look like at the top of your layout.Master page?

Thanks again!

11/22/2010 3:53:30 PM
Gravatar
Total Posts 245
mojoPortal Community Expert

Re: Strange Layout Behavior when adding inline code to site layout.Master

I use this type of code in my apps main xxxxxxxxxx.aspx page code-behind page.

Yes, I have a App_MasterPages folder with a layout.master file in my project folder, but it is just there as a place holder to allow compiling.

What I did have to do to get some Telerik code to work correctly with my app was to change my skin layout master as follows.

Here  is the first 2 lines from my skins layout.master

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="~/App_MasterPages/layout.Master.cs"
    Inherits="mojoPortal.Web.layout" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

NOTE: The second line is Telerik.

Then in the same layout.master  I needed to replace this...

<asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server" />

With this 

<telerik:RadScriptManager ID="RadScriptManager1" runat="server" enablepartialrendering="true"
    asyncpostbacktimeout="600" enablepagemethods="true">
    <Scripts>
        <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
        <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
    </Scripts>
</telerik:RadScriptManager>
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" EnableAJAX="true">
</telerik:RadAjaxMana ger>

If you don't need RadAjaxManager you do not need the last 2 lines.

I only say this because you say you are using in-line scripts which would need a scriptmanager.  If you are using scripts that are to work with Telerik controls you should use the Telerik script manager.

If you search the forums on "RadScriptManager1" you will find an old thread from 1.5 years ago where me and another developer figured this out.

There, now I have opened up a whole can of worms and you will regret I ever answered your post.surprise

Arivixe.com

Rick

 

11/23/2010 9:03:29 AM
Gravatar
Total Posts 18439

Re: Strange Layout Behavior when adding inline code to site layout.Master

Hi,

I would not recommend adding any C# code in layout.master, it already has a code behind file that is compiled into mojoPortal.Web.dll and it already has a page load event so adding one may break it.

You should wrap your menu inside a UserControl (.ascx) and embed that in layout.master and use the page load event of the usercontrol. This is no different than how <portal:SiteMenu works and is included in layout.master.

In fact if you really want to to make a menu using RadMenu you should study the code from our source code for Web/Controls/SiteMenu.ascx.cs where you can see how to bind to the sitemapdatasource and how to filter for role membership (instead of using an xml file).

SiteMenu is basically a wrapper control that wraps around <asp:Menu and <asp:TreeView and a few variations thereof that use CSS Control adapters. Bascially you want to implement a similar wrapper control but use RadMenu instead of the <asp:Menu, but other than that the logic should be very similar to what we have in SiteMenu, so studying/copying the code there should help you.

Then you just use your control instead of SiteMenu in layout.master.

Best,

Joe

11/23/2010 11:16:14 AM
Gravatar
Total Posts 18

Re: Strange Layout Behavior when adding inline code to site layout.Master

Joe,

Thank you for the information and the suggestion...that definitely sounds like the best approach and I'll attempt to put that solution into action this morning.

Thanks again!

11/23/2010 2:29:50 PM
Gravatar
Total Posts 18

Re: Strange Layout Behavior when adding inline code to site layout.Master

Amazing...that worked perfectly Joe. I simply set the datasource for my RadMenu and did a DataBind() and then added an ItemDataBound event to the RadMenu and modified the code a bit to support RadMenu and it works. I think I'll go back and remove some of the variables that aren't needed now, but what a great solution.

11/24/2010 11:51:17 AM
Gravatar
Total Posts 18439

Re: Strange Layout Behavior when adding inline code to site layout.Master

Glad to hear it Philip!

Best,

Joe

You must sign in to post in the forums. This thread is closed to new posts.