Copied to clipboard

Flag this post as spam?

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


  • Harm-Jan Abbing 62 posts 102 karma points
    May 06, 2010 @ 10:34
    Harm-Jan Abbing
    0

    Doc2Form not rendered after custom dataype

    Hi all,

    I'm having some trouble with a custom datatype in a Doc2Form eh, form.

    The form works perfectly without the control, and the control always works. It's just a label that checks the querystring for a nodeid and shows the nodename of the node with that id. Yet every textfield or button that's supposed to show below that label doesn't get rendered. I had another simple user control on the same page that shows text after a button click and when i click it, the remaining fields of the form appear. So i guess it's a postback issue.

    I'm rather new to creating usercontrols and datatypes in .net for Umbraco so i'm sure i've overlooked something.

    Any help is much appreciated!

    (Umbraco v4.0.3)

    Greets,
    Harm

  • Chris Dunn 210 posts 401 karma points
    May 06, 2010 @ 22:15
    Chris Dunn
    0

    Sounds like it's not a large control, can you post the code behind and html  source for your user control? Might save some of the back and forth questions.

    -Chris

  • Harm-Jan Abbing 62 posts 102 karma points
    May 07, 2010 @ 11:17
    Harm-Jan Abbing
    0

     

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="NodenameByQs.ascx.cs" Inherits="UmbracoCustomDatatypeNodenameByQs.NodenameByQs" %>
    <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using umbraco.presentation.nodeFactory;
    
    namespace UmbracoCustomDatatypeNodenameByQs
    {
    
        public partial class NodenameByQs : System.Web.UI.UserControl, umbraco.editorControls.userControlGrapper.IUsercontrolDataEditor
        {
            public string umbracoValue;
            public int nodeid;
            Node mynode;
    
            protected void Page_Load(object sender, EventArgs e)
            {
    
                if (!String.IsNullOrEmpty(Request.QueryString["id"]))
                {
                    nodeid = int.Parse(Request.QueryString["id"]);
                    mynode = new Node(nodeid);
    
                    Label1.Text = mynode.Name;
                }
            }
    
            public object value
            {
                get
                {
                    return umbracoValue;
                }
                set
                {
                    umbracoValue = value.ToString();
                }
            }
        }
    }

  • Sergio Nunes 15 posts 36 karma points
    Nov 02, 2011 @ 12:45
    Sergio Nunes
    0

    Hi guys!

    Has anybody solved this problem ? I'm facing the same situation here.

    Thanks

    Sergio Nunes

     

  • Gregg Duncan 48 posts 70 karma points
    Jan 26, 2012 @ 18:35
    Gregg Duncan
    0

    I was having this same issue. After digging into it a bit I found that the Doc2Form.cs was calling the set method of my custom datatype and passing it a null value. This, of course, throws the dreaded 'Null Reference Exception' in the set method when using "value.ToString()'. However the error gets suppressed by a try/catch block. So it doesn't tell you what the error is. It just quits building the form.

    Fortunatelyl, the fix for this is very easy. In the 'Set' method of any custom datatype, check the 'value' for null and set a default value if null is passed. Here's an example of my 'Value' property from my custom datatype.

            public object value
    {
    get
    {
    myvalue = string.Empty;

    foreach (ListItem item in ddlmyvalues.Items)
    {
    if (item.Selected)
    myvalue = item.Value;
    }
    return myvalue;
    }
    set
    {
    if (value == null) value = string.Empty;
    myvalue = value.ToString();
    }
    }

    I hope this helps anyone else out there having the same problem. If you find that it solves your problem please mark this post accordingly. Also a High Five would be much appreciated.

    Happy coding fellow Umbracians.

Please Sign in or register to post replies

Write your reply to:

Draft