Customize SharePoint Server 2010 People selection feature-replace default click events

Source: Internet
Author: User
Tags visual studio 2010

Article Summary

In the previous article said do not want to modify the default system files, then we have to find a way to let users click the book icon is to open our custom page, we first look at the click on the book icon to do what, and then see what we can do.

Click on the book icon to do something

Right-click book icon-check elements we can see these things.

<aID= "Ctl00_placeholdermain_ctl00_ctl01_userpicker_browse"title= "Browse"onclick= "__dialog__ctl00_placeholdermain_ctl00_ctl01_userpicker (); return false;"href= "javascript:"><imgtitle= "Browse"src= "/_layouts/images/addressbook.gif"alt= "Browse"style= "border-width:0px;"></a>

Just click on the time to call the method! There is nothing difficult, the specific method is what to do, nothing is to open the window of some operations. That's good, let's just replace the method.

Replace default method

The code is very simple, if you want to refer to jquery.

$ ("#控件ID"). Removeattr ("onclick");

Now, it doesn't seem to work, it just works in the debug console, I want to be able to replace it when it's running, what should I do? The whole site, where the code is written where can the whole site work?

    1. Template page, this needless to say, the entire site is using the template page;
    2. Through Elements.xml, the JS code is registered to the global website;

Or the back of this method, the next method through development, the code package into a function, I want to use the time to enable the function, do not want to use the time to close the function, reliable ...

Register Global JS

Visual Studio 2010, create a SharePoint solution that adds a project to an empty element.

<? XML version= "1.0" encoding= "Utf-8" ?> <  xmlns= "http://schemas.microsoft.com/sharepoint/">
  < CustomAction       scriptsrc = "/_layouts/custompicker/pickeragent.js"       Location= "ScriptLink"      Sequence= ">  " </ CustomAction > </ Elements >

Nothing to say, customaction I do not know, the specific baidu,google,bing, his function far more than these.

Scriptsrc:js file path, all put into the Layouts folder, this does not need to ask why it;

Location: Fixed, tell SharePoint that this is a JS;

Sequence: It is said that this is a priority of what things, if the two customaction conflict, the greater the value of the higher priority;

Wait, the replacement method has, that id how I get to, as if the ID of each control is different ah ...

Gets the control ID

No nonsense, directly on the code

$(function() {Userpicker ();});functionUserpicker () {//Find all controls ending with "_userpicker"    varAlluserpickercontrol = $ ("span[id$= ' _userpicker ')"); //Traverse These controlsAlluserpickercontrol.each (function(index, domele) {//get the user control ID        varUserpickercontrolid = $ ( This). attr ("id"); //gets the ID of the user Control book icon        varUserpickercontrolpickerid = Userpickercontrolid + "_browse"; //Remove the original Click event for the Select button$ ("#" + Userpickercontrolpickerid). Removeattr ("onclick"); $("#" +Userpickercontrolpickerid). Unbind (); //Add a new event$ ("#" + Userpickercontrolpickerid). Click (function () {            //Open Window MethodOpenpickeruserdialog (userpickercontrolid);    }); });}

The following will open the custom window ...

Customize SharePoint Server 2010 People selection feature-replace default click events

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.