ASPX templates
Version 3.x > ASPX templates > Accessing Form Data Programatically View modes: 
User avatar
Member
Member
imuir@amplifystudios.com - 6/19/2008 10:30:58 AM
   
Accessing Form Data Programatically
I've added a field to many of the items in my site called Sidebar. In the code-behind for my template, I need to check if the current page has a value you for sidebar and if not, load the sidebar of the parent item.

I can retrieve the TreeNode of the current document pretty easily by using the CMSContext.CurrentDocument, but there doesn't seem to be any way to get to the field data.

How would I access data from one of these fields via code-behind?

User avatar
Member
Member
kentico_vitaja - 7/1/2008 7:16:31 AM
   
RE:Accessing Form Data Programatically
Hi,

If your TreeNode is properly loaded by CMSContextCurrentDocument then you should be access your fields by GetValue() method. Here is simple example:

CMS.TreeEngine.TreeNode node = tree.SelectSingleNode(CMSContext.CurrentSite.SiteName, aliaspath, TreeProvider.ALL_CULTURES);
node.GetValue("myproperty");

Best regards,
Vita Janecek

User avatar
Member
Member
rahat.veraida-gmail - 12/14/2011 5:22:05 AM
   
RE:Accessing Form Data Programatically
kentico_vitaja wrote: Hi,

If your TreeNode is properly loaded by CMSContextCurrentDocument then you should be access your fields by GetValue() method. Here is simple example:

CMS.TreeEngine.TreeNode node = tree.SelectSingleNode(CMSContext.CurrentSite.SiteName, aliaspath, TreeProvider.ALL_CULTURES);
node.GetValue("myproperty");

Best regards,
Vita Janecek


We tried the following:
TreeNodeDataSet dataset = TreeHelper.SelectNodes("/%", true, "custom.course", "CourseID = " + courseID);

where courseID is a valid ID of a document of type custom.course.
When we expanded the "result view" in the debug mode we can see that the In the "DocumentName" and the "DocumentNamePath" values are also loaded properly.
But the "Items" property of the dataset is throwing an error:

"base {System.SystemException} = {"Unable to cast object of type 'CMS.TreeEngine.TreeNodeCollection' to type 'CMS.TreeEngine.TreeNodeCollection`1[CMS.TreeEngine.TreeNode]'."}"

Any Idea what we might be doing wrong?

User avatar
Member
Member
kentico_michal - 12/14/2011 6:26:20 AM
   
RE:Accessing Form Data Programatically
Hello,

I suppose you are using Kentico CMS 6.0, so I would like to ask you to use the forum for Kentico CMS 6.0 next time you post some question.

In terms of your issue, could you please apply the latest hotfix for Kentico CMS 6.0. This seems to be a bug that has been already fixed. You can use Kentico Installation Manager to apply the latest hotfix: Kentico Installation Manager.

Best regards,
Michal Legen