1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Current PageID

Current PageID

2 posts, 0 answered
  1. Himanshu Jain
    Himanshu Jain avatar
    5 posts
    Registered:
    06 Jul 2012
    24 Sep 2009
    Link to this post
    Hi
    I have gone through a thread for Current PageID:-
    http://www.sitefinity.com/support/forums/sitefinity-3-x/developing-with-sitefinity/getting-current-page-id.aspx

    But the solutions given in this thread are not working in my code and produces following errors:-

    Code 1 :
    protected void Page_Load(object sender, EventArgs e)  
        {  
           Guid pageID = ((Telerik.Cms.Web.UI.PageEditor)(this.Parent.Parent.Parent.Parent.Parent.Parent)).SelectedPageId;  
        }  
      
    This code gives following error:-
    Error : Unable to cast object of type 'ASP.sitefinity_admin_modules_aspx' to type 'Telerik.Cms.Web.UI.PageEditor
    ---------------------------------------------------------------------------------------------------------
    Code 2 :
    protected void Page_Load(object sender, EventArgs e)
        {
            CmsManager man = new CmsManager();
            ICmsUrlContext page = (ICmsUrlContext)this.Context.Items[UrlHelper.CmsPageKey];
            string Id = page.PageID.ToString();
        }

    Error : In this, the object 'page' is null
    ---------------------------------------------------------------------------------------------------------
    Code 3 :
    Guid pageID = ((Telerik.Cms.Web.UI.PageEditor)(this.Parent.Parent.Parent.Parent.Parent.Parent)).SelectedPageId;

    Error : {"Unable to cast object of type 'ASP.sitefinity_admin_modules_aspx' to type 'Telerik.Cms.Web.UI.PageEditor'."}

    Can anyone please help me and give me the way to get the current PageID
    Thanks in advance
    Himanshu Jain

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    24 Sep 2009
    Link to this post
    Hello Himanshu Jain,

    As I see it from the error you are trying to add the code to Admin/Modules.aspx. The code works if you add it to one of the page templates located under Sitefinity/Admin/ControlTemplates/Pages/

    I hope this helps.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
2 posts, 0 answered