[Original] how to embed custom controls in dataformwebpart [How to embeded custom control in dfwp]

Source: Internet
Author: User
Tags xslt

The dataformwebpart (dfwp) control is a widely used data display control in Sharepoint. It defines the data source and XSLT to display the data, and controls the data accordingly. In SharePoint designer, you can configure the Code view and the designer view. This gives me the illusion that dataformwebpart allows you to insert custom controls into it.

I add my custom control to a location in dataformwebpart.

 
<Only: savebuttonex Runat= "Server" Isclientredirect= "True" Redirectmessage= "Data is successfully saved" ControlMode= "New" ID= "Savebutton1" />

But when I do this, the result is:

I'm dizzy. SharePoint designer crashes directly ~~~~

Okay, it seems that the crash caused by adding my custom control to dataformwebpart. Then I try to add the control using XSLT.

 <  XSL: Element   Name = "Only: savebuttonex"  >      <  XSL: attribute   Name  = "Runat"  > Server </  XSL: attribute  >      <  XSL: attribute   Name  = "Redirectmessage"  > Data is saved </  XSL: attribute  >      < XSL: attribute   Name  = "Isclientredirect"  > True </  XSL: attribute  >      <  XSL: attribute   Name  = "ControlMode"  > New </  XSL: attribute  >      <  XSL: attribute   Name  = "ID"  > Btnsave </  XSL: attribute  >  </  XSL: Element  > 

This time, Spd won't crash, but what is displayed in the design view is:

The prompt shows that there is no namespace in XSLT in dataformwebpart. You can find the location of the namespace defined in dataformwebpart and add the namespace of my control to XSL: stylesheet:

 <  XSL: stylesheet   Xmlns: x  = "Http://www.w3.org/2001/XMLSchema"   Xmlns: DSP  = "Http://schemas.microsoft.com/sharepoint/dsp"   Version  = "1.0"   Exclude-result-prefixes  = "XSL msxsl ddwrt"   Xmlns: ddwrt  = "Http://schemas.microsoft.com/WebParts/v2/DataView/runtime"   Xmlns: ASP  = "Http://schemas.microsoft.com/ASPNET/20"  Xmlns :__ designer  = "Http://schemas.microsoft.com/WebParts/v2/DataView/designer"   Xmlns: XSL  = "Http://www.w3.org/1999/XSL/Transform"   Xmlns: msxsl  = "Urn: Schemas-Microsoft-com: XSLT"   Xmlns: SharePoint  = "Microsoft. Sharepoint. webcontrols"   Xmlns: ddwrt2  = "Urn: FrontPage: Internal"  Xmlns: only  = "Only. splibraryextend. webcontrols"  > 

Let's look at the design view:

It is finally displayed. Is that all done? Let's take a look in the browser:

the prompt is that my custom tag cannot be parsed. I carefully read the source code, on the above page, I clearly wrote <% @ register tagprefix = "only" namespace = "only. splibraryextend. webcontrols "assembly =" splibraryextend, version = 1.0.0.0, culture = neutral, publickeytoken = 77c9affec54a974f "%>? In addition, if only: savebuttonex is not defined in my source code, what should be the problem with the design view of the page? The problem is deadlocked again. I thought about it carefully. If there is no problem in the design view and there is a problem during running, it must be a problem in the processing of dataformwebpart, so return to dataformwebpart. Well, use the decompilation tool to check its Code , I was surprised when I saw the following code.

  protected   string  [] _ assemblyreferences =  New   string  [] { "<% @ register tagprefix = \ "SharePoint \" namespace = \ "Microsoft. sharepoint. webcontrols \ "assembly = \" Microsoft. sharepoint, version = 14.0.0.0, culture = neutral, publickeytoken = 71e9bce111e9429c \ "%>" ,  "<% @ register tagprefix = \" groupboard \ "namespace = \" Microsoft. sharepoint. applications. groupboard. webcontrols \ "assembly = \" Microsoft. sharepoint, version = 14.0.0.0, culture = neutral, publickeytoken = 71e9bce111e9429c \ "%>" }; 

Originally, dataformwebpart was forced to reference only two tagprefixes in it, so what I added to the entire page didn't work at all. _ Assemblyreferences is a field and also protected. Fortunately, dataformwebpart is not sealed and can be inherited. Well, I will inherit one.

[Designer ( Typeof (Dataformwebpartdesigner), supportsattributemarkup (True ), Xmlroot (namespace = Http://schemas.microsoft.com/WebPart/v2/DataView" ), Parsechildren ( True ), Aspnethostingpermission (securityaction. linkdemand, level = aspnethostingpermissionlevel. Minimal), using pointpermission (securityaction. linkdemand, objectmodel = True ), Aspnethostingpermission (securityaction. inheritancedemand, level = aspnethostingpermissionlevel. Minimal), using pointpermission (securityaction. inheritancedemand, objectmodel = True )] Public   Class Dataformwebpart: Microsoft. Sharepoint. webpartpages. dataformwebpart { Public Dataformwebpart ():Base () {_ Assemblyreferences = New   String [] { "<% @ Register tagprefix = \" SharePoint \ "namespace = \" Microsoft. sharepoint. webcontrols \ "assembly = \" Microsoft. sharepoint, version = 14.0.0.0, culture = neutral, publickeytoken = 71e9bce111e9429c \ "%>" , "<% @ Register tagprefix = \" groupboard \ "namespace = \" Microsoft. sharepoint. applications. groupboard. webcontrols \ "assembly = \" Microsoft. sharepoint, version = 14.0.0.0, culture = neutral, publickeytoken = 71e9bce111e9429c \ "%>" ,"<% @ Register tagprefix = \" only \ "namespace = \" only. splibraryextend. webcontrols \ "assembly = \" splibraryextend, version = 1.0.0.0, culture = neutral, publickeytoken = 77c9affec54a974f \ "%>" };}}

I have redefined _ assemblyreferences In the constructor and added the tagprefix of my own control.

Similarly, modify the tag of dataformwebpart in SharePoint designer to point it to my own control. After this operation, I tried to re-change the savebuttonex control defined in XSLT <only: savebutton runat = "server" isclientredirect = "true" redirectmessage = "data is successfully saved" ControlMode = "new" id = "savebutton1"/>, and SPD is no longer crashed.

Run the page to see the effect:

There is no problem with the display. The savebuttonex control is Part 1.ArticleControl the client jump, to see the effect:

Success ~~

For the implementation of savebuttonex, see: http://www.cnblogs.com/fxwdl/archive/2012/08/30/2663093.html

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.