Copied to clipboard

Flag this post as spam?

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


  • rwm 5 posts 22 karma points
    Nov 18, 2009 @ 17:37
    rwm
    0

    Listing the published polls - null reference

    I am trying to create a usercontrol to display all published polls. The control loops through the children of the polls node and dynamically creates Poll.ascx controls and adds them to a placeholder.

    This works fine when I include the control in a plain ASPX page. However, when I create a macro for the control and add it to an Umbraco page, I get null reference exceptions. I believe it has something to do with the UpdatePanel, because, while the panel itself is not null, all of its child controls are.

    I tried to create the Poll controls earlier in the page lifecycle by adding them in Page_Init on the poll-list control, but the Page_Init function does not seem to be executed when the control is included via a macro. (It is executed when the control is included on a plain ASPX page.)

    This may not be specific to the Poll project, but does anyone know why the control would work within an ASPX page but not within an umbraco macro?

    I'm using umbraco 4 and the latest poll package, with .NET 2.0.

  • Tim Geyssens 6562 posts 15373 karma points MVP 2x c-trib
    Nov 18, 2009 @ 17:47
    Tim Geyssens
    1

    Haven't tried doing that. Multiple polls on the same page is possible. Could you post your code ?

  • rwm 5 posts 22 karma points
    Nov 18, 2009 @ 18:43
    rwm
    0

    It's pretty simple -- LoadPolls() gets called on Page_Load & pollParentID is a public property. The markup for this control has a script manager and a Panel, nothing else.  Poll.ascx is unchanged. I get a null reference in Poll.ascx.cs the first time it tries to reference a child control of the updatepanel (the first line of RenderQuestion, where it references pnlResults.Visible).

    Again, this all works when I put my control into an ASPX page, but not when I use it in an umbraco page via a macro.

      private void LoadPolls()

        {
            Document parentDoc;
            try
            {
                parentDoc = new Document(pollParentID);
            }
            catch (ArgumentException exc)
            {
                return;
            }

            foreach (Document pollDoc in parentDoc.Children)
            {
                if (pollDoc.Published)
                {
                    Poll uc = (Poll)Page.LoadControl("~/usercontrols/poll.ascx");

                    pnlPolls.Controls.Add(uc);

                    uc.PollNodeId = pollDoc.Id;
                    uc.ID = "Poll" + pollDoc.Id.ToString();

                }
            }
        }

     

    Thanks for looking.

    -Ryan

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies