SharePoint Study Notes-delegate control-create custom searchbox

Source: Internet
Author: User

Sometimes we need to develop a custom searchbox to replace the default searchbox of the masterpage of the SharePoint website. This requires the delegate controls knowledge. The delegate control of Sharepoint is like a container, which encapsulates various default controls. These controls can be replaced by custom controls developed by users to achieve user-defined functions and effects.

SharePoint provides many delegate controls:

• Additionalpagehead
• Globalsitelink0
• Globalsitelink1
• Globalsitelink2
• Publishingconsole
• Quicklaunchdatasource
• Smallsearchinputbox
• Topnavigationdatasource

Below are some delegate controls defined by masterpage of SharePoint fundation.

< SharePoint: delegatecontrol Runat = "Server" Controlid = "Additionalpagehead"  
Allowmultiplecontrols = "True" />
< SharePoint: delegatecontrol Runat = "Server" Controlid = "Globalnavigation"   />
< SharePoint: delegatecontrol Runat = "Server" ID = "Globaldelegate0" Controlid = "Globalsitelink0"   />
< SharePoint: delegatecontrol Controlid = "Globalsitelink2" ID = "Globaldelegate2" Scope = "Farm"
Runat = "Server"   />
< SharePoint: delegatecontrol Runat = "Server" Controlid = "Publishingconsole"  
ID = "Publishingconsoledelegate" >
</ SharePoint: delegatecontrol > < SharePoint: delegatecontrol Controlid = "Globalsitelink3" Scope = "Farm"  
Runat = "Server"   />
< SharePoint: delegatecontrol Runat = "Server" Controlid = "Smallsearchinputbox" Version = "4"   />
< SharePoint: delegatecontrol Runat = "Server" Controlid = "Topnavigationdatasource"  
ID = "Topnavigationdelegate" />

The delegate controls listed above can be dynamically replaced by custom controls or feature at runtime. The custom searchbox creation function we need to implement here needs to be implemented by replacing the delegate control of small search input box with the mysearchbox user control we developed.

Let's take a look at the delegate control's XML schema.

<? XML version = "1.0" encoding = "UTF-8" ?> < Elements Xmlns = "Http://schemas.microsoft.com/sharepoint" > < Control ID = "Smallsearchinputbox" Sequence = "100" Controlsrc = "/Templates/mysearchcontrol. ascx" /> </ Elements >

From the schema above, we can see that the important attributes of delegate control includeControl ID,SequenceAndControlsrc.

Control IDIt is used to identify the delegate control.

Sequence NumberIs used to locate the level of the delegate control. The smaller the value, the higher the level.

ControlsrcIs used to specify the location of the control resource of the delegate control.

 

The sequencenumber can be further illustrated


 

In the example, three user controls are defined for the same delegate control and enabled through three feature (A, B, C, they have different sequence (A> C> B). All three user controls are used to replace the specified delegate control. However, because the sequence number of Feature B is the smallest, the usercontrol in Feature B will get the final replacement right at runtime and be rendered in page by render. However, when Feature B is stopped, feature C will replace it because the sequence in feature C is second only to feature B. When Feature B is stopped, feature C becomes the smallest, therefore, it will win the final victory.

The delegate control page is also listed in the layouts directory of SharePoint. That is to say, when you modify some delegate control, some of the following pages that use this delegate control will also be affected.

• Addnavigationlinkdialog. aspx: controlid = "addnavigationlinkdialogpanel1" scope = "site"
• Addnavigationlinkdialog. aspx: controlid = "addnavigationlinkdialogpanel2" scope = "Web"
• Areanavigationsettings. aspx: controlid = "navigationsettingspanel1" Scope = "Site"
• Areanavigationsettings. aspx: controlid = "navigationsettingspanel2" Scope = "Web"
• Backlinks. aspx: controlid = "smallsearchinputbox"
• Excelprofilepage. aspx: controlid = "variationsflagcontrol"
• Excelprofilepage. aspx: controlid = "globalsitelink1" Scope = "Farm"
• Excelprofilepage. aspx: controlid = "globalsitelink2" Scope = "Farm"
• Groups. aspx: controlid = "quicklaunchdatasource"
• Listcontentsources. aspx: controlid = "quicklaunchdatasource"
• Listservernamemappings. aspx: controlid = "quicklaunchdatasource"
• Logsummary. aspx: controlid = "quicklaunchdatasource"
• Logviewer. aspx: controlid = "quicklaunchdatasource"
• Managecrawlrules. aspx: controlid = "quicklaunchdatasource"
• Managefiletypes. aspx: controlid = "quicklaunchdatasource"
• Manageprivacypolicy. aspx: controlid = "quicklaunchdatasource"
• Manageservicepermissions. aspx: controlid = "quicklaunchdatasource"
• Mycontactlinks. aspx: controlid = "colleagueslink1" Scope = "Farm"
• Newsbweb. aspx: controlid = "createsitepanel1" scope = "site"
• People. aspx: controlid = "quicklaunchdatasource"
• Personalsites. aspx: controlid = "quicklaunchdatasource"
• Profmain. aspx: controlid = "quicklaunchdatasource"
• Quicklinks. aspx: controlid = "addcolleagueslink1" Scope = "Farm"
• Regionalsetng. aspx: controlid = "regionalsettingsextensions"
• Schema. aspx: controlid = "quicklaunchdatasource"
• Scsignup. aspx: controlid = "createsitecollectionpanel1" scope = "farm"/>
• Searchsspsettings. aspx: controlid = "quicklaunchdatasource"
• SiteManager. aspx: controlid = "globalsitelink1" Scope = "Farm"
• SiteManager. aspx: controlid = "globalsitelink2" Scope = "Farm"
• User. aspx: controlid = "quicklaunchdatasource"
• Userdisp. aspx: controlid = "profileredirection" scope = "farm"
• Versiondiff. aspx: controlid = "smallsearchinputbox"
• Viewlsts. aspx: controlid = "quicklaunchdatasource"
• Viewscopes. aspx: controlid = "quicklaunchdatasource"
• Xlviewer. aspx: controlid = "globalsitelink1" Scope = "Farm"
• Xlviewer. aspx: controlid = "globalsitelink2" Scope = "Farm"

 

With the above knowledge, go back to the goal of this article and create a custom searchbox.

Create a new project, add a new user control to the project, and drag and drop a calendar control in the user control, this calendar control is used to show how to replace the default searchbox control.

 

Project Example

Then, we need to add a feature in the system. The name of this feature is as follows:

In this feature, we define that the scope is site-level, which means that the search control on your entire site page will be replaced with your own custom style.

Next, we need to add a new elment. XML, as shown in.

Note that the sequence attribute value must be smaller than the default value. The sequence value is 100 in WSS, 50 in Moss Standard Edition, and 25 in Enterprise Edition.

Search for the corresponding XML file in the specified feature in the moss installation directory and open it to view the sequence value defined in it (Name: searcharea. XML ).

Finally, compile and deploy and open our test website to see the effect as shown in.

 

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.