SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

For a project I'm working on, I'd like to get a Page_Load C# method behind a Document Library, but I've been unable to achieve this, so far. Any help would be greatly appreciated!

Some details on what I'm trying to achieve: Every user gets a list on their MySite section where they can input certain Labels. Then they can add these Labels to specific documents. Users should only see labels they've added themselves. I already have code for creating and managing these labels, as well as the personal lists. I'm simply unable to fill in the correct information when the user loads the Document Library.

Thanks in advance!

share|improve this question
up vote 0 down vote accepted

In order to add custom code-behind to a page (such as viewing a Document Library) you have a few options:

1) Add a custom web part to that page.

2) Add a custom control to the master page.

3) Add a custom control via a delegate control.

I prefer the third option with the AdditionalPageHead delegate control. This lets you add your own custom user control to every SharePoint page. In your situation, you could use the SPContext.Current.List object to determine if you are on your document library and then do what you need to do. I have a blog post about creating a basic AdditionalPageHead delegate control:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.