|
|
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
|
|
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
|
|
 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
|
|
Rank: Devotee
Joined: 7/20/2006 Posts: 48 Location: Copenhagen, Denmark
|
I'm using Umbraco 3.0.3 on XP Udblog.dk
|
|
 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
|
|
 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());
SqlCommand deleteOld = new SqlCommand("delete from xtraContentTag where contentnode = " + Request["id"], conn);
conn.Open();
deleteOld.ExecuteNonQuery();
conn.Close();
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
|
|
|
Guest |