Get NodeID in a Filter Control

Eric Garrison asked on March 22, 2016 15:38

I am having an issue with a Custom Control (ascx.cs) file and could use assistance. The only issue I am having is getting the NodeID of the page I am on. The control needs to populate a drop down with sub categories. That works fine if I hard code my NodeID, but I am not having any luck getting the NodeID of the page.

The page is a standard page in the PORTAL engine. What is the syntax and command for NodeID in ASCX.CS?

Correct Answer

Anton Grekhovodov answered on March 22, 2016 17:57

Hi Eric,

Just use DocumentContext.CurrentDocument.NodeID

3 votesVote for this answer Unmark Correct answer

Recent Answers


Dawid Jachnik answered on March 22, 2016 15:43

Hello,

If your control inherits from FormEngineUserControl, you can get NodeID by this

ValidationHelper.GetInteger(Form.GetFieldValue("NodeID"), 0)

or did you tried with CurrentPageInfo.NodeID ?

3 votesVote for this answer Mark as a Correct answer

Eric Garrison answered on March 22, 2016 16:54

I am getting an error. Here is my code. When I uncomment nodeID=1458, and remove your code, it works. I did declare the nodeID as INT above this.

String dataDB = "Kentico9";

QueryDataParameters qdp = new QueryDataParameters();

nodeID = ValidationHelper.GetInteger(Form.GetFieldValue("NodeID"), 0)

///nodeID = 1458;

qdp.Add("NodeID", nodeID);

DataSet ds = ConnectionHelper.ExecuteQuery(string.Format("{0}.dbo.GetCycleTypeList", dataDB), qdp, QueryTypeEnum.StoredProcedure,true);

Exception type: System.Web.HttpCompileExceptionStack Trace: at System.Web.Compilation.BuildManager.PostProcessFoundBuildResult(BuildResult result, Boolean keyFromVPP, VirtualPath virtualPath)at System.Web.Compilation.BuildManager.GetBuildResultFromCacheInternal(String cacheKey, Boolean keyFromVPP, VirtualPath virtualPath, Int64 hashCode, Boolean ensureIsUpToDate)at System.Web.Compilation.BuildManager.GetVPathBuildResultFromCacheInternal(VirtualPath virtualPath, Boolean ensureIsUpToDate)at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate)at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate)at System.Web.Compilation.BuildManager.GetVPathBuildResult(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean ensureIsUpToDate)at System.Web.UI.TemplateControl.LoadControl(VirtualPath virtualPath)at CMS.ExtendedControls.ControlDefinition.Load(Page page)at CMSWebParts_Filters_Filter.LoadFilter()Machine name:

0 votesVote for this answer Mark as a Correct answer

Virgil Carroll answered on March 22, 2016 17:24

Eric,

Have you looked at all at using the DocumentContext object for this instead? If you are on 8 or 9, I would really recommend that. You could then use the DocumentContext GetValue to get the NodeID in that? It is a more efficient way of getting this in these versions.

1 votesVote for this answer Mark as a Correct answer

Eric Garrison answered on March 22, 2016 21:00

Sorry I cannot give 2 correct answer votes.

Here is what I added: nodeID = ValidationHelper.GetInteger(DocumentContext.CurrentDocument.NodeID,0);

Make sure you have using CMS.DocumentEngine; in the top of your ASCX.CS

0 votesVote for this answer Mark as a Correct answer

Anton Grekhovodov answered on March 23, 2016 04:56

Eric,

It's not necessary to use ValidationHelper.GetInteger here, because DocumentContext.CurrentDocument.NodeID returns int value.

1 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.