Copied to clipboard

Flag this post as spam?

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


  • Josh Olson 79 posts 207 karma points
    Jan 24, 2013 @ 12:29
    Josh Olson
    0

    Populate asp controls in template with values from logged in member properties

    Using Umbraco 4.11.1 w/ SQL Server Express & WebMatrix

    Here is what I am trying to do.  I have created a form using asp controls directly in my template as such:

    <asp:TextBox ID="TextBoxFirstName" runat="server" CssClass="panelMainTextBox"></asp:TextBox>

    I would like to populate the textbox (and other asp controls) with values from custom properties of the logged in member.  I know how to access these properties in a razor macro, ie:

    @using umbraco.cms.businesslogic.member
        @{
            var member = Member.GetCurrentMember();
           
            var userName = member.Text;
            var first = member.getProperty("firstName").Value.ToString();
            var last = member.getProperty("lastName").Value.ToString();
           
            <div>Username: <span style="float:right">@userName</div><br />
            <div>First Name: <span style="float:right">@first</div><br />
            <div>Last Name: <span style="float:right">@last</div>       
        }

    but what I cannot figure out how to do is assign those values to the various asp controls.

    I believe that most people tend to use Visual Studio to create forms, but I have no expierence using the program and I tend to be much more comfortable coding things by hand (although I am not opposed to using VS Web Developer if there is an easy way to do so). If this is the better way of doing things, can someone please point me in the direction of how to create the form in VS Web Developer, populate the fields from the member data, and from there move it over to my Umbraco site.

    Also, I have looked into Contour, and although it is a really excellent piece of software, it is terribly difficult to customize if you don't like the standard look, feel, or behavior (yes I know you can in the new version, and I have messed around with it, but there are too many things that it dosen't do that I want for it to be a useful solution).

    Thanks in advance!

    - Josh

  • Nigel Wilson 945 posts 2077 karma points
    Jan 24, 2013 @ 18:46
    Nigel Wilson
    0

    Hi Josh

    Personally I think the best way to proceed is to develop your forms within a user control, then create a macro and link the macro to the user control and then drop the macro on the template and populate the fields in the Page_Load event of the user control.

    This does mean using Visual Studio.

    Good luck

    Nigel

  • Josh Olson 79 posts 207 karma points
    Jan 25, 2013 @ 08:50
    Josh Olson
    0

    Hey Nigel,

    Thanks for the input.  I have a followup question if I may.  What do you think of using regular HTML control tags (ie. <fieldset>, <input>, etc.) in a .cshtml macro?  I have been expiermenting a bit and it seems to be working out for me so far.  It is quite easy to access the custom member properties that I created in the macro and assign the values to the various HTML controls.  Is this going to cause me problems later following this path? (As you may have guessed, I do not have much expierence with this type of thing.  This is my first attempt at using .net anything so I am still fumbling around a bit).  In looking at the source code for Contour rendered forms, I see that it is using HTML controls also (the very thing that tiped me off to the possibility) so I figured if it is good enough for Contour...

    Cheers!

    Josh

Please Sign in or register to post replies

Write your reply to:

Draft