Textbox in Usercontrol Wrapper not working ? Options
martinbentzen
Posted: Tuesday, January 29, 2008 7:07:56 PM
Rank: Devotee

Joined: 7/20/2006
Posts: 48
Location: Copenhagen, Denmark
What have I done wrong in the following code ?

I've tried to make my own datatype - in this example just as a simple textbox, and then wrap is as a datatype. I used the "FTP-datatype-in-45-min..." datatype as inspiration.

But it doesn't work. I can use the datatype (type some texts into it), and save the page. When re-enter the page, the content in the textbox isn't saved. When looking in the database, no content has been added for this property.

Code:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace myDatatype
{
    public partial class input : System.Web.UI.UserControl, umbraco.editorControls.userControlGrapper.IUsercontrolDataEditor
    {
        public string umbracoValue;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack)
            {
                if (!String.IsNullOrEmpty(TextBox1.Text))
                {                   
                    umbracoValue = TextBox1.Text;
                }
            }
            TextBox1.Text = umbracoValue;
        }
        #region IUsercontrolDataEditor Members

        public object value
        {
            get
            {
                return umbracoValue;
            }
            set
            {
                umbracoValue = value.ToString();
            }
        }

        #endregion
    }
}


Thanks in advantage

/Martin

Udblog.dk
martinbentzen
Posted: Wednesday, January 30, 2008 2:46:53 PM
Rank: Devotee

Joined: 7/20/2006
Posts: 48
Location: Copenhagen, Denmark
Hmmm,

This is strange... if I use a Label control instead of a Textbox (and have a button which populate the Label.Text), then I have no problem with wraping my usercontrol as a datatype, and save the content.

Are there any other that have tried to make a datatype by wrapping a usercontrol containing a Textbox control ?

/Martin

Udblog.dk
tim
Posted: Wednesday, January 30, 2008 3:56:13 PM

Rank: Addict

Joined: 2/19/2007
Posts: 564
Location: Belgium
Wierd, what version are you running this on ?

Umbraco tips and tricks: http://www.nibble.be - umbraco mvp 08/09 - certified level 1 & 2 professional
martinbentzen
Posted: Wednesday, January 30, 2008 4:04:20 PM
Rank: Devotee

Joined: 7/20/2006
Posts: 48
Location: Copenhagen, Denmark
I'm using Umbraco 3.0.3 on XP

Udblog.dk
hoehler
Posted: Wednesday, January 30, 2008 4:06:10 PM

Rank: Addict

Joined: 7/19/2006
Posts: 572
Location: Bad Homburg, Germany
Try
Code:

namespace myDatatype
{
    public partial class input : System.Web.UI.UserControl, umbraco.editorControls.userControlGrapper.IUsercontrolDataEditor
    {

        protected void Page_Load(object sender, EventArgs e)
        {
        }
        #region IUsercontrolDataEditor Members

        public object value
        {
            get
            {
                return TextBox1.Text;
            }
            set
            {
                TextBox1.Text = value.ToString();
            }
        }

        #endregion
    }
}

That's what I have done with a more complex datatype, but I think (my guess in the dark) your problem is the order of the page-load and the property.

Thomas

• 2007/2008 MVP • www.thoehler.com • Bad Homburg, Germany
tim
Posted: Wednesday, January 30, 2008 4:08:50 PM

Rank: Addict

Joined: 2/19/2007
Posts: 564
Location: Belgium
I have this running , don't see what the problem might be

Code:

namespace TG.Umb.TagCloudDataType
{
    public partial class TagCloud : UserControl, umbraco.editorControls.userControlGrapper.IUsercontrolDataEditor  
    {
        public string umbracoValue;

        protected void Page_Load(object sender, EventArgs e)
        {
            
            if (Page.IsPostBack)
            {
                SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["umbracoDbDSN"].ToString());
                
                //delete old values
                SqlCommand deleteOld = new SqlCommand("delete from xtraContentTag where contentnode = " + Request["id"], conn);
                conn.Open();
                deleteOld.ExecuteNonQuery();
                conn.Close();

                //insert new
                string[] TagsCollection = txtTags.Text.Split(new char[] { ' ' });

                foreach (string Tag in TagsCollection)
                {

                    SqlCommand insertNew = new SqlCommand("insert into xtraContentTag(tag, contentnode) values(@tag,@contentnode)", conn);
                    insertNew.Parameters.AddWithValue("@tag", Tag.ToUpper());
                    insertNew.Parameters.AddWithValue("@contentnode", Convert.ToInt32(Request["id"]));

                    conn.Open();
                    insertNew.ExecuteNonQuery();
                    conn.Close();

                }



                umbracoValue = txtTags.Text.ToUpper();

            }

            
            txtTags.Text = umbracoValue;

          
        }

        #region IUsercontrolDataEditor Members

        public object value
        {
            get
            {
                return umbracoValue;
            }
            set
            {
                umbracoValue = value.ToString();
            }
        }

        #endregion
    }
}


Umbraco tips and tricks: http://www.nibble.be - umbraco mvp 08/09 - certified level 1 & 2 professional
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.