Copied to clipboard

Flag this post as spam?

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


  • codestuff 2 posts 20 karma points
    Feb 04, 2009 @ 14:46
    codestuff
    0

    Using page fields in a C# User control

    Hi

    I'm fairly new to Umbraco. I've been evaluating v3 for most 2008 (in spare time) and over the last two months have built our company website on v4. Thanks for all the hard work on v4 and for producing an excellent product.

    I'm starting to add some of the more advanced features to the website, one being the addition of a download page that emails the user a link back to the actual downloadable resource.

    I've got most of this working using a UserControl however I now need to pull the UpLoad File field vlaue from the page and place it in the email!

    Can anyone tell me how to access the page fields from a UserControl or how to pass them in via the public properties?

    I've search the forum and google but maybe I'm using the wrong terms. All I found was the following posting which asks the same question but with no answers.

    http://forum.umbraco.org/yafpostst2295passing-values-to-net-user-controls-from-umbraco.aspx

    Thansk in advance for any help and sorry if this turns out to be so obvious!!!

    Cheers

    Dave

  • codestuff 2 posts 20 karma points
    Feb 04, 2009 @ 15:06
    codestuff
    0

    Ha

    A little more digging and I found the solution - really I have spent a good 2 days on this! Sorry for the what now seems a silly post to me.

    For reference for those like me :-) the solution is as follows



    where resFileResource is a page field in the document type.


    Cheers

    Dave

  • Nik Wahlberg 639 posts 1237 karma points MVP
    Feb 04, 2009 @ 16:29
    Nik Wahlberg
    0

    Good work, that is the way to do it.

    Let us know if you run into anything else.

    Cheers,
    Nik

  • David Conlisk 432 posts 1008 karma points
    Jun 29, 2009 @ 11:29
    David Conlisk
    2

    Hi Dave,

    An alternative solution, as mentioned by Casey and Morten in the forum post you reference, is to use the API to access the values. I generally use an UmbracoHelper class in my Web Application project for use in my user controls. Thus in your user control you can write:

    string strPropertyOfCurrentPage = UmbracoHelper.GetCurrentNodeProperty("propertyAlias");

    This way you can implement error checking and throw explicit exceptions, for examle if the property alias doesn't exist on the current node.

    See my blog post here for more, and the source code for my UmbracoHelper class (which includes other helpful methods like this):

    http://web-garden.co.uk/2009/3/28/an-update-to-my-umbraco-helper-class.aspx

  • Peter Gregory 408 posts 1614 karma points MVP 3x admin c-trib
    Jun 29, 2009 @ 13:48
    Peter Gregory
    1

    @codestuff if you find the solution, or if someone else provides the correct solution, can you please remember to mark that post as the solution as this helps others find it quicker and the thread also is marked as resolved.

    Great to hear that worked it out.

    Peter Gregory  

Please Sign in or register to post replies

Write your reply to:

Draft