Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Zakhar 171 posts 397 karma points
    Jan 07, 2013 @ 17:23
    Zakhar
    0

    How to set a page title from usercontrol and access it in razor script?

    I need to set a page title programmatically on some pages, but still be able to display the value from Umbraco if it's not set. How can I do it?

    In my usercontrol PageLoad I do:

    Page.Title = "My title";

    I want to access it in my razor script, something like this:

    string title = Page.Title;

    if (string.IsNullOrEmpty(title)) {
        title = Model.Title;
    }

    It doesn't work though, how can I do it?

     

  • Edwin van Koppen 156 posts 270 karma points
    Jan 10, 2013 @ 10:02
    Edwin van Koppen
    0

    Normaly it's the ViewBag.Title.. can't you set that?

  • Zakhar 171 posts 397 karma points
    Jan 10, 2013 @ 10:37
    Zakhar
    0

    I need to do it from codebehind of .ascx usercontrol, I can't use ViewBag, can I?

  • Edwin van Koppen 156 posts 270 karma points
    Jan 10, 2013 @ 10:57
    Edwin van Koppen
    0

    You say from codebehind? Why, can't you do in razor?

     

    string title = Page.Title;

    if (string.IsNullOrEmpty(title)) {
        ViewBag.Title = Model.Title;
    }

     

  • Zakhar 171 posts 397 karma points
    Jan 10, 2013 @ 11:50
    Zakhar
    0

    I use Facebook api and load albums from Facebook, display image gallery using usercontrol and want to assign page title according to album name. I load the usercontrol using Umbraco macros.

    If I assign Page.Title in usercontrol's PageLoad and then try to access it in razor script (which is on the same page, but obviously has nothing to do with the usercontrol above) it is null.

    So in codebehind I have :

    protected void Page_Load(object sender, EventArgs e) {

       ...

       Page.Title = "my title";

       ...

    }

    in razor script

    string title = Page.Title // it's null

    Basically my question is how can I pass any string from usercontrol to Umbraco context and how to access it (from template or macros script)? It's NOT necessary to use Page.Title, any way will do.

  • Edwin van Koppen 156 posts 270 karma points
    Jan 11, 2013 @ 15:05
    Edwin van Koppen
    0

    Sorry that i don't have that answer...

Please Sign in or register to post replies

Write your reply to:

Draft