Copied to clipboard

Flag this post as spam?

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


  • Carl 15 posts 36 karma points
    Sep 08, 2011 @ 19:18
    Carl
    0

    Pass node information to net user control

    Hello all, 

    I am using Umbraco for a training/event registration site and running into a small issue.

    I have a list of courses using XSLT (the user can click on course and see details) . I also have a simple net user control registration form (just sends a e-mail to admin) that I manually create a drop down list of all the courses on the site and the user selects the course, fills out registration information and submits. The site will have 75+ courses and I don't think its a good idea to keep adding courses manually.

    I would like the nodeID information to be passed to the .net user control registration form depending on what course the user selects. I looked at the node factory api but I'm not sure on how to start. Any ideas?

    Thank you

  • Nigel Wilson 944 posts 2076 karma points
    Sep 08, 2011 @ 20:01
    Nigel Wilson
    0

    Hi Carl

    Could you have the URL's to the registration form appended with query string data ? e.g. registration.aspx?courseID=1234

    Then on page load of the user control you could check for the query string data and do stuff accordingly.

    Cheers

    Nigel

  • Euan Rae 105 posts 135 karma points
    Sep 08, 2011 @ 20:11
    Euan Rae
    1

    If you're .net user control is on the course detail page, then you can use the umbraco.NodeFactory.Node.GetCurrent(); to get the current node.  You can then use the 'node' object to get information about that particular course.

    If the registration form is on a different page, then you can pass the node id of the node containing all the courses and iterate through them to fill your drop down list.

    To do this in your usercontrol create a public property that's an int e.g. 'CoursesNodeId'.  In the macro for your usercontrol, create a macro parameter with the same name e.g.  'CoursesNodeId'.

    Then your code needs to do something like:

    protected void Page_Load(object sender, EventArgs e)
            {
                if (!Page.IsPostBack)
                {
                    LoadCourses();
                }
            }
            private void LoadCourses()
            {
                Node coursesNode = new Node(CoursesNodeId);
     
                foreach (Node course in coursesNode.Children)
                {
                    ddlCourses.Items.Add(new ListItem(course.Name, course.Id.ToString()));
                }
            }
            public int CoursesNodeId
            {
                get;
                set;
            }
     

    Hope that's what your after

  • Carl 15 posts 36 karma points
    Sep 08, 2011 @ 20:33
    Carl
    0

    Thanks Nigal, Thats a good idea. I could grab the @nodeName on the net control registration page with

    Request.QueryString["@nodeName"];

    My concern is the course names are rather long. Is there a way to pass the @id in the quary and then use the node node factory net control to find the @nodeName or any other information related to that node?

    If so, this just might be what I was looking for

     

    Thank you

  • Euan Rae 105 posts 135 karma points
    Sep 08, 2011 @ 20:35
    Euan Rae
    0

    This will pass the node id: Request.QueryString["@id"];

    Then you can use

    Node courseNode = new Node(int.Parse(Request.QueryString["id"]))

    string nodeName = courseNode.Name;


  • Carl 15 posts 36 karma points
    Sep 08, 2011 @ 20:43
    Carl
    0

    Hey Euan,

    Thanks for your reply. You are very close. The only point is I don't want a drop down list on the registration form. I'm only using a manual drop down now because I don't know which course they are intrested in (I'm typing each course in)

    All the courses are on a course list template with a xslt course list macro

    The registration page is a net control on its own page. Currently the two do not communicate with each other.

  • Euan Rae 105 posts 135 karma points
    Sep 08, 2011 @ 20:52
    Euan Rae
    0

    Ah, I see.

    In that case, your best bet is to do what Nigel suggested and pass the node id in the query string.  Then you can use the API as above to get the node information

  • Carl 15 posts 36 karma points
    Sep 08, 2011 @ 21:13
    Carl
    0

    Thanks Nigal and Euan,

     

    I will try Nigal's solution tonight and update with the complete code to help others.

  • Carl 15 posts 36 karma points
    Sep 08, 2011 @ 22:47
    Carl
    0

    Hello, I'm running into another issue as I'm setting up my @id to pass.

     

    Which is the best way to pass the ID using XSLT?

    The registration form is located at http://somesite.com/register.aspx

    The goal is for each course to pass its id so it looks like this http://somesite.com/register.aspx?course=1234 etc, etc

    and I would catch the ID using Request.QueryString["id"]

    I was trying something like this, but got stuck

              <xsl:element name=”a”>

    <xsl:attribute name=”href”>

    <xsl:value-of select=””/>

    </xsl:attribute>

    <xsl:value-of select=”./”/>

    </xsl:element>

     

     

  • Euan Rae 105 posts 135 karma points
    Sep 08, 2011 @ 22:58
    Euan Rae
    0

    Assuming that the page you are linking from is the relevant course node, you could use something like

    <a>

    <xsl:attribute name="href">

    <xsl:text>/register.aspx?id=</xsl:text>

    <xsl:value-of select="$currentPage/@id"/>

    </xsl:attribute>

    Click here to register

    </a>

  • Carl 15 posts 36 karma points
    Sep 08, 2011 @ 23:15
    Carl
    0

    Thanks Euan,

    Thats the tricky part...sorta. Another issue popped up. My layout looks like this

    Courses ID 1234

    - Course A  ID 1020

    - Course B ID 2010

    - Course C ID 2014

    When I click on "register now" on any course 1234 shows up (the parent)

    Any Ideas?

     

    Thank you in advance!

     

     

  • Euan Rae 105 posts 135 karma points
    Sep 08, 2011 @ 23:24
    Euan Rae
    0

    OK, I'm assuming what you're doing to display the courses is something like

     

    <xsl:for-each select="$currentPage/courseNode">

    <ul>

    <li>

    <xsl:value-of select="umbraco.GetXmlNodeById(@id)/@nodeName"/>

    <a>

    <xsl:attribute name="href">

    <xsl:text>/register.aspx?id=</xsl:text>

    <xsl:value-of select="@id"/>

    </xsl:attribute>

    Click here to register

    </a>

    </li>

    </ul>

    </xsl:for-each>

     

    I've put the updated line in bold and red - if you are doing it the way I'm guessing this should fix your problem

  • jjhone66 1 post 21 karma points
    Sep 17, 2011 @ 17:04
    jjhone66
    0

    Thanks for this blog post. You consistently write a intriguing post. Thanks!

Please Sign in or register to post replies

Write your reply to:

Draft