Sign up ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I want to get the ID/Name of the DocumentLibrary when I Click/Select on any library from List of libraries from the Left Panel of MasterPage.

Can I call the function from MasterPage or where ? How ?

share|improve this question

1 Answer 1

You haven't mentioned exactly in what context (server/client) however via ECMA Javascript is quite easy (somehow irrelevant if you are in the master page at the time of execution) -

var value = SP.ListOperation.Selection.getSelectedList(id);

See more here

I use a similar function on a Ribbon button. You might want to combine this call with ExecuteOrDelayUntilScriptLoaded (see more here

function getSelectedIds() {
                        var ctx = SP.ClientContext.get_current();
                        var items = SP.ListOperation.Selection.getSelectedItems(ctx);
                        var selectedItems = '';
                        for (index in items) {
                            selectedItems = selectedItems + ',' + items[index].id;
                        return selectedItems.substring(1, selectedItems.length);

Still, considering that actual request and the purpose of a master page, i still fail to see a situation when you would considering adding such a constraint (or need) into your master page. May I suggest you rather consider using Delegate controls (an example here

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.