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!


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: http://www.sharepointjohn.com/sharepoint-2010-programmatically-add-javascript-meta-tags-and-css-styles-to-the-header-of-every-page/

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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