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

Forums / Developing with Sitefinity / Run code for a page at runtime

Run code for a page at runtime

6 posts, 0 answered
  1. Jason Green
    Jason Green avatar
    53 posts
    Registered:
    18 Sep 2009
    11 Dec 2009
    Link to this post
    At runtime when a Sitefinity page is loaded I want to modify some of the meta data and do things to controls that may be on the page.
     
    How do I do this?
     
    Is there a delegate or event I can use to tap into the Sitefinity page at runtime?  If so where would the code that needs to run reside, and how do I get the page to call it.
     
    I should note this is NOT all pages, just some pages.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    13 Dec 2009
    Link to this post
    Hi Jason Green,

    To get a certain page you can use one of the following ways described in our Developer Manual. To change the metadata of this page you need to clear the Page.Header.Controls and then using HtmlMeta ASP.NET class you can create a new metakeys for this page. Another option is accessing the ICmsPage object properties lile Keywords, Description, Title.

    CmsManager cmsManager = new CmsManager();
    ICmsPage p = (ICmsPage)cmsManager(new Guid("45D6C81A-FD17-4be1-B95C-29CF482049DF");
    p.Title = "some title";
    p.Description = "something";
    p.Keywords = "test";
    cmsManager.SavePage(p);


    All the best,
    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.
  3. Jason Green
    Jason Green avatar
    53 posts
    Registered:
    18 Sep 2009
    13 Dec 2009
    Link to this post
    I saw how to do it programically, but I don't want to save the page that way.  I want to dynamically change those fields at runtime so I can use the page as a template and have the content dynamically served.

    How do I do what you described in the page load process, so it is done without saving over the original values.?

    What I am doing is I have a page that is mapped via advanced URL Rewriting and based on some variables pulled from the URL we load different content in the user controls.  I want to modify the meta data depending on the variables loaded.
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    13 Dec 2009
    Link to this post
    Hi Jason Green,

     Create a user control and drop it on your page. Then on load or PreRender event execute the logic below.  The two options are - using HtmlMeta or working with the page and calling SavePage method.


    Greetings,
    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.
  5. Kieran
    Kieran avatar
    56 posts
    Registered:
    14 Aug 2008
    03 Mar 2010
    Link to this post
    I was looking for the same solution.

    I just removed the

     

    <asp:ContentPlaceHolder ID="head" runat="server">

     

     

    </asp:ContentPlaceHolder>

     


    from the template replaced with

    <

     

    asp:Literal ID="metaDetails" runat="server" />

     



    In my control I access the literal and set the text to the appropriate values

    Literal

     

    lit = (Literal)Page.Master.FindControl("metaDetails");

     

    lit.Text =

    "<title></title><meta name=\"keywords\" content=\"\" ><meta name=\"description\" content=\"\" >";

    Seems to work fine.

    Kieran

     

  6. Jason Green
    Jason Green avatar
    53 posts
    Registered:
    18 Sep 2009
    09 Mar 2010
    Link to this post
    For me, I wanted to keep the settings that were being set, just process them for any "tokens" based on current context from another process.

    I was able to do this in the pre_render of a custom internal page processing the entire page HTML before it output to the browser.  Not only does it work for the meta data, it works for all content from all modules on all pages.  It turned out to be a very simple solution for what could have been a complex problem.
Register for webinar
6 posts, 0 answered