+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / master page

master page

10 posts, 0 answered
  1. Shairyar
    Shairyar avatar
    3 posts
    Registered:
    23 Feb 2009
    13 Jul 2009
    Link to this post
    Hi,

    Hope someone can help me, I am new with SF. I cant see any codebehind files of master pages, is this how it is supposed to be or am i missing something? reason i am asking this is because i am planning to use RadControls and for that i wanted to write a code, is there any other file where i go to write a code? I tried to create a codebehind file of communitymain.master (communitymain.cs) and got an error when i compiled it that this class already exists.

    Many thanks,
    Baig
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    13 Jul 2009
    Link to this post
    Hi Shairyar,

    You should be able to create a code behind of each master file. However the better solution is that you should work with user controls which you will drop on you master template through Sitefinity UI instead of hard coding them to a master page.

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Shairyar
    Shairyar avatar
    3 posts
    Registered:
    23 Feb 2009
    13 Jul 2009
    Link to this post
    Dear Ivan,
    Thanks, if i get you right it means when i drop the control to master page there is an option in that control to have ajax effect? I am just looking to update certain content pannel of the page not the whole page to postback.

    Regards,
    Shairyar
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    13 Jul 2009
    Link to this post
    Hi Shairyar,

    First you need to crate a ContentPlaceHolder on your master page. Then work with user controls. In a user control you can use RadAjaxManager with Panel control and RadAjaxloadingPanel.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  5. Shairyar
    Shairyar avatar
    3 posts
    Registered:
    23 Feb 2009
    15 Jul 2009
    Link to this post
    Dear Ivan,

    Thanks, thats what leads me back to my first question that do i need to put anything in code behind files or i can just drag the RadAjaxManager to the master page and do what ever desired? my main question is that do i need code behind file at all for master page to use RadAjaxManager.

    Regards,
    Shairyar
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    15 Jul 2009
    Link to this post
    Hello Shairyar,

    Generally you do not need a code behind for your master page when you are going to use custom and user controls which will be responsible for the logic.

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  7. Michael Park
    Michael Park avatar
    13 posts
    Registered:
    23 Oct 2009
    17 Nov 2009
    Link to this post
    If I did want to create a master page code behind, to set the page theme programatically based on a query string, how would I do that?  Where do I upload it?  Should I upload using the admin, or open the project and compile it, or have a code block in the master page?

    Is the master page the best place to put that kind of logic?  Can I extend the base page class somehow?
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    17 Nov 2009
    Link to this post
    Hi Michael Park,

    If you add the logic to your master page code behind, you actually will hard code it which is not good practice. You should use user or custom controls. For Sitefinity it does not matter from where you will upload the file. In both cases it is located under App_Master directory. However the way that suggest for changing the theme is creating a custom class that inherits from Internal page and then overriding OnPreInit method.

    sample code:

    MyInternalPage : InternalPage
        {
            protected override void OnPreInit(EventArgs e)
            {
                if (!String.IsNullOrEmpty(this.Request.QueryString["templateName"]))
                {
                    string tName = this.Request.QueryString["templateName"];
                    this.newTemplate = this.Manager.GetTemplate(tName);
                }
      
                base.OnPreInit(e);
            }
          private IPageTemplate newTemplate = null;
      }

    You need to override GetMasterPageName, GetTheme and AddPageControls methods and set newTemplate.Theme.

    Finally you need to replace the default internal page and set the newly created

    ~/Sitefinity/cmsentrypoint.aspx

    <%@ Page Inherits="Telerik.Sitefinity.Samples.MyInternalPage" MasterPageFile="~/Sitefinity/Dummy.master" %>

    Regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  9. Michael Park
    Michael Park avatar
    13 posts
    Registered:
    23 Oct 2009
    17 Nov 2009
    Link to this post
    So how should I override GetMasterPageName, GetTheme and AddPageControls methods?  What is IPageTemplate and when/where should I set the theme of the newTemplate?  I see in the sample that we are setting a PageTemplate but not sure how that relates to a page theme.  I'm new to Sitefinity so am used to just setting Page.Theme and not sure how sitefinity does things. 
  10. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    17 Nov 2009
    Link to this post
    Hello Michael Park,

    IPageTemplate is an interface that inherits from IPage, IPageContent, IPageBase, IPagesContainer. It defines a cms page template. I overrode the methods for you:

    protected override string GetMasterPageName(Telerik.Cms.IPageContent pageContent)
            {
                // override this if you want to change only the master page
                return base.GetMasterPageName(pageContent);
            }
      
            protected override string GetTheme(IPageContent pageContent)
            {
                if (this.newTemplate != null)
                {
                    if (pageContent != null && String.IsNullOrEmpty(pageContent.Theme))
                        return newTemplate.Theme;
                }
                return base.GetTheme(pageContent);
            }
      
            protected override void AddPageControls(Telerik.Cms.IPageContent pageContent, System.Collections.Generic.Dictionary<string, System.Web.UI.WebControls.ContentPlaceHolder> placeHolders)
            {
                if (pageContent is IPageTemplate && this.newTemplate != null)
                {
                    pageContent = newTemplate;
                }
                base.AddPageControls(pageContent, placeHolders);
            }

    More information at Working with pages

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Register for webinar
10 posts, 0 answered