Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Find current page ID to use in webpart

  Asked By: Mayur    Date: Mar 07    Category: Sharepoint    Views: 5214

I have this little webpart with a button that is displayed beneath
the contents on all wiki pages. When the button is clicked I'd like to
display a popup window with the page ID (column ID) number, like "You
are on wiki page with ID=47" and then do some logic depending on the
ID number.

How can I find out the ID of the wiki page displayed on same page as
my webpart, please?

namespace Web_Part1
[XmlRoot(Namespace = "Web_Part1")]
public class Web_Part1 : WebPart
SPSite site = new SPSite("http://sharepoint");
HtmlButton _mybutton;

public void _mybutton_click(object sender, EventArgs e)
//Find out which wiki page is being displayed, and get ID
for it

protected override void CreateChildControls()
_mybutton = new HtmlButton();
_mybutton.InnerText = "Current Page ID";
_mybutton.ServerClick += new EventHandler(_mybutton_click);

protected override void RenderWebPart(HtmlTextWriter output)



1 Answer Found

Answer #1    Answered By: Dhanraj Saxsena     Answered On: Mar 07

Is your ultimate goal simply to display the ID, or do you have a more
functional need?

To get the ID, try this:

String ListId, ItemId;

SiteContext = SPContext.GetContext(HttpContext.Current);

if (SiteContext != null)
ListId = SiteContext.List.ID.ToString();

ItemId = SiteContext.ListItem.ID.ToString();

Didn't find what you were looking for? Find more on Find current page ID to use in webpart Or get search suggestion and latest updates.