Usercontrol wrapper for custom datatype Options
sfxpete
Posted: Wednesday, August 13, 2008 2:21:01 PM
Rank: Devotee

Joined: 9/5/2007
Posts: 65
Hi,

I'm tring to use the usercontrol wrapper for my own custom datatype. I've started out with a little test that I can't get working! I wanted to emulate the 'Textstring' datatype. I'm using the following code..

Code:
namespace ipr
{
    public partial class myTextDataType : UserControl, umbraco.editorControls.userControlGrapper.IUsercontrolDataEditor
    {
        public string umbracoValue;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack)
            {
                umbracoValue = myBox123.Text;
            }
            else
            {
                myBox123.Text = umbracoValue;
            }
        }

        #region IUsercontrolDataEditor Members

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

        #endregion

    }
}


..and the following presentation code...

Code:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="myTextDataType.ascx.cs" Inherits="ipr.myTextDataType" %>
<asp:TextBox ID="myBox123" runat="server"></asp:TextBox>


I create the datatype just fine and it renders fine. When I type in a value and save it however nothing gets persisted. I set a breakpoint in the page load and found that on postbacks nomatter what I've typed in the Textbox the myBox123.Text is empty which explains why nothing is getting saved. Bigger question is why I don't see anything in that property on the postback (I can still see my text in the rendered webpage after the postback which is very odd!)? Any ideas? Ta!
Ethan
Posted: Monday, August 18, 2008 9:53:12 PM
Rank: Newbie

Joined: 8/18/2008
Posts: 10
Location: Iowa
Did you have to call Page_Load() or was that called for you?

I have pretty much the exact same code and Page_Load() isn't even called. I have to call it manually in OnLoad();

Oh, and I have the same problem.

-E

Ethan
Posted: Monday, August 18, 2008 10:28:12 PM
Rank: Newbie

Joined: 8/18/2008
Posts: 10
Location: Iowa
You'll probably get a kick out of this.

Since I don't know when Page_Load() is supposed to occur in the .NET page loading process (and neither does anyone else apparently), I used OnPreRender() and that fixed the problem.

From what I can tell the ASP.NET page loading process goes in this order:
".NET framework initialization" -> page initialization where OnInit() is called -> page state processing which is where state related post data is loaded -> OnLoad() is called -> all other data is loaded from the request -> OnPreRender() -> rendering

So the last possible hook to initialize your stuff is OnPreRender().

psterling@homax
Posted: Monday, August 18, 2008 11:28:47 PM

Rank: Fanatic

Joined: 10/30/2007
Posts: 214
Location: Bellingham
Here's a nice reference to the ASP.NET page lifecycle that I keep bookmarked:

http://msdn.microsoft.com/en-us/library/ms178472(VS.80).aspx

-Paul

motusconnect.com :: level-2 certified :: MVP 2008/2009
Ethan
Posted: Tuesday, August 19, 2008 9:39:31 PM
Rank: Newbie

Joined: 8/18/2008
Posts: 10
Location: Iowa
This problem still isn't solved. If I do all my editing OnPreRender then nothing saves to the database at all. When I do it OnLoad only non text box controls are saved.

So far I've encountered about 4 posts on this forum all asking about this and nobody gives an answer. Come on people. Someone's gotta know what's going on.
Ethan
Posted: Wednesday, August 20, 2008 5:24:52 PM
Rank: Newbie

Joined: 8/18/2008
Posts: 10
Location: Iowa
I didn't exactly fix the problem but I found a wacky way around it:

Code:

protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);

            //Instantiate the CMS Node that you're currently on, in my case its a Media
            ThisEvent = new Media(int.Parse(this.Request.QueryString["Id"]));

            if (Page.IsPostBack)
            {
                //Do your stuff here ...

                                //When you're done, manually invoke save on your CMSNode
                                This.Event.Save();
            }
        }
anvimi
Posted: Sunday, October 05, 2008 6:41:15 PM
Rank: Newbie

Joined: 9/19/2008
Posts: 11
Does anyone know to get the current content node from a custom datatype usercontrol? I'm stuck.

Don't worry, I've already found the answer here
Dirk
Posted: Sunday, October 05, 2008 7:03:30 PM

Rank: Addict

Joined: 9/27/2007
Posts: 977
Location: Belgium
Hi,

Not sure if it would work, but I guess you can parse the node's id using the querystring.

A custom datatype user control is intended to be used on a node, right? Have a look at left bottom corner when hovering a content node, this way you'll find out what page is requested, and more interestingly, what querystring will be used to build the page on which the custom datatype usercontrol is placed?

Does this help?

Regards,
/Dirk


level 1 certified - umbraco blog at netaddicts.be - working on an integrated forum4umbraco
anvimi
Posted: Sunday, October 05, 2008 7:06:12 PM
Rank: Newbie

Joined: 9/19/2008
Posts: 11
Thank you, Dirk. It's OK.
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.