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

Forums / Developing with Sitefinity / getting Current Page ID

getting Current Page ID

6 posts, 1 answered
  1. Gokhan
    Gokhan avatar
    32 posts
    Registered:
    11 Jul 2008
    08 Sep 2009
    Link to this post
    Hi ;

    For some functioanlity i need to get pageid of the page which is currently  being edited. I tried to get this from "PagePropertiedEdit.ascx"  by following code snippet

    Guid pageID = ((Telerik.Cms.Web.UI.PageEditor)(this.Parent.Parent.Parent.Parent.Parent.Parent)).SelectedPageId;

    My problem is this code is returning previous Pageid sometimes.I couldnt find out the problem but i need to click navigation twice to get correct PageID. Can you help me pls ? it is urgent. Thank you 

    I m using Sitefinity 3.6 , Visual Studio 2005
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    08 Sep 2009
    Link to this post
    Hi Gokhan,

    Below is a sample code that illustrates how to get the current page ID.

    CmsManager man = new CmsManager(); 
    ICmsUrlContext page = (ICmsUrlContext)this.Context.Items[UrlHelper.CmsPageKey]; 
    string Id = page.PageID.ToString(); 

    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.
  3. Gokhan
    Gokhan avatar
    32 posts
    Registered:
    11 Jul 2008
    08 Sep 2009
    Link to this post
    I m trying to get Pageid from "PagePropertiesEdit.ascx" and "SitemapPanel.ascx". The code snippet above returns null in this case. am i doing something wrong ?
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    08 Sep 2009
    Link to this post
    Hi Gokhan,

    Do you call the code below on a Page_Load ? I tried it and the ID was returned correctly.

    protected void Page_Load(object sender, EventArgs e)  
        {  
           Guid pageID = ((Telerik.Cms.Web.UI.PageEditor)(this.Parent.Parent.Parent.Parent.Parent.Parent)).SelectedPageId;  
        }  
      
     

    Sincerely yours,
    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.
  5. Gokhan
    Gokhan avatar
    32 posts
    Registered:
    11 Jul 2008
    08 Sep 2009
    Link to this post
    i m trying to get in in user control  "PagePropertiedEdit.ascx" like this.

     protected override void OnLoad(EventArgs e)
        {        Guid pageID =((Telerik.Cms.Web.UI.PageEditor)(this.Parent.Parent.Parent.Parent.Parent.Parent)).SelectedPageId;
    //do something
    }

    It is returning a value but pageid of the page which i clicked previously on sitemap. Why? 
  6. Nikolai
    Nikolai avatar
    216 posts
    Registered:
    01 Jun 2017
    16 Sep 2009
    Link to this post
    Hello Gokhan,

    The problem comes from the fact that every time you click on the page tree the page gets pre-rendered.
    So all you need to do is to add this in the OnPreRender event.
    For example:
    <asp:LinkButton ID="LinkButton1" OnPreRender="PreRen"  CommandName="Submit" runat="server" CssClass="CmsButLeft okdark" ValidationGroup="PageProperties"
    protected void PreRen(object a, EventArgs e) 
            {             
                Guid pageID = ((Telerik.Cms.Web.UI.PageEditor)(this.Parent.Parent.Parent.Parent.Parent.Parent)).SelectedPageId; 
                var manager = new Telerik.Cms.CmsManager(); 
                Telerik.Cms.IPage page = manager.GetPage(pageID); 
                Response.Write(pageID.ToString() + "-" + page.Name.ToString()); 
            } 


    Regards,
    Nikolai
    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.
    Answered
Register for webinar
6 posts, 1 answered