kamagra how much to take

Customzing Connection Information Using The FilterInfoBar Class

Ok, I am done with my rants, I probably could have brought up 15 other subjects, but I will quit now. I was kinda enjoying not doing something entirely technical on this blog and expressing my feelings about some things, but apparently several people took exception to my writing, particularly some recruiting companies I work with. :)

In this post, I am going to explain to you how to use the FilterInfoBar class, which is responsible, as you can probably guess, for controlling enhanced information that is displayed when a WebPart, such as one that is inheriting from the ITransformableFilterValues (ITransformableFilterValues will be responsible for sending filter values to the consumer) interface as we will see shortly, is appropriately connected in the orthodox provider / consumer fashion. Modifying your WebPart to include the FilterInfoBar class (which can function like the default connection types that SharePoint provides by hiding it except in design mode if you want), provides people that are going to use your WebPart insight into the current connection settings that they have. For this reason, it makes good business sense to incorporate with your connectible WebPart deliverables.

So, let’s say that you are having a very exciting morning because you are developing your first custom filter WebPart, thereby developing by inheriting from some new fun interfaces, particularly in this case, you are going to be inheriting from ITransformableFilterValues out of the Microsoft.SharePoint.WebPartPages namespace (as discussed earlier). So therefore, when decorating your WebPart class file, you will have to structure it as such:

  1. public class AdamsFilter : WebPart, ITransformableFilterValues

Then, once you have read the remainder of this post, you can call your new FilterInfoBar control just like any child control by doing a Controls.Add(YourNewInfoBar()), after instantiating it as a new object (I am not going to go over Filter WebParts to that extent in this post, perhaps in another if there is appropriate interest) within your overridden CreateChildControls() method.

The ITransformableFilterValues interface is important when writing your provider filter WebPart since it is responsible for the actual passing of the value to the consumer WebPart, and provides access to crucial filter properties that will control the actual behavior of the passing of values (like whether multiple values can be passed to the consumer through the use of the AllowMultipleValues property, which is a very clutch decoration since you can then have multiple provider points to a singular consumer, which I find just awesome).

Now you want to define a new FilterInfoBar class in your filter WebPart in order to provide some textual information to users that are responsible for building the relevant connection out, or maybe just to yourself for debugging purposes. Firstly, make your appropriate references in your new class:

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Web.UI.WebControls.WebParts;
  5. using AspNetControl = System.Web.UI.Control;
  6. using SharePointFilterInfoBar = Microsoft.SharePoint.WebPartPages.FilterInfoBar;

Afterwards, get your namespace going and decorate your class inheritance so that it is set to inherit from your SharePointFilterInfoBar class (we are going to be using the imported reference as written above, therefore simply set the class inheritance as FilterInfoBar or whatever your namespace assignment is):

  1. namespace adams.Examples
  2. {
  3.  
  4. // this inheritance is deriving from the import reference we establish above
  5. class AdamsFilterInfoBar : SharePointFilterInfoBar
  6. {
  7.  
  8. }
  9.  
  10. }

Now you have something going, but you haven’t structured the information display that should be rendered to the user when this class is called from your filter WebPart, so this isn’t very interesting at all. Because you desire to grab this connection information BEFORE the WebPart is rendered, you have to override the OnPreRender event so that these values are available before the actual HTML is rendered out to the user (since these values will be a part of the interface that you are providing your users with). Following your override, your class file should then have this structure.

  1. namespace adams.Examples
  2. {
  3.  
  4. class AdamsFilterInfoBar : FilterInfoBar
  5. {
  6.  
  7. protected override void OnPreRender( EventArgs e )
  8. {
  9.  
  10. }
  11. }
  12.  
  13. }

Now we need to inject the code that we will actually trigger during the OnPreRender process. Firstly, you must take note that the FilterInfoBar class object hierarchy, in order to understand how to structure the code. FilterInfoBar looks like this:

System.Object
System.Web.UI.Control
System.Web.UI.WebControls.WebControl
Microsoft.SharePoint.WebPartPages.FilterInfoBar

The FilterInfoBar class is useless unless it is a child of another control, it MUST be bound to another parent control by which it can read the relevant values and display said values within textual information that is relevant to the user (or where the hell else is it going to get the connection values :) ). Therefore, you can ensure that your FilterInfoBar class is the sub of a parent control by simply doing a Parent property reference which will ensure a parent control in the page control hierarchy (not a necessity in the code, however a nice to have, and simple requires testing the parent for a null reference by getting the Parent property of the current instance of the class , i.e. if(Parent == null)).

Now with the OnPreRender method, you start to develop the actual code that will be responsible for displaying that contextual information to the user. In order to iterate through the connections that are available, you are going to use a WebPartConnection object, since this is responsible for providing the functionality that will allow two WebParts to manifest a communication, iterating for these objects using a WebPartManager object which has a Connections property. Ultimately, your loop will look like this:

  1. foreach ( WebPartConnection l_oConnection in WebPartManager.Connections )
  2. {
  3. // This will return all the WebPartConnection objects.
  4. }

Once you have the loop to iterate through the entire Connection object set up, you can start to use the results in order to build conditional results that are output to the user. Depending on whether you are integrating your custom FilterInfoBar class into a provider or consumer will heavily impact the output. Fortunately, there is a property that allows you to distinguish between the two so that the output can be controlled, namely the WebPartConnection.Consumer and WebPartConnection.Provider, which you put against the parent control. Within your foreach loop, you can distinguish between them like this:

This will allow you to test whether the parent control is a Provider:

  1. foreach ( WebPartConnection l_oConnection in WebPartManager.Connections )
  2. {
  3. if (Parent.Equals(l_oConnection.Provider))
  4. }

and this will allow you test whether your parent control is a Consumer:

  1. foreach (WebPartConnection l_oConnection in WebPartManager.Connections)
  2. {
  3. if (Parent.Equals(l_oConnection.Consumer))
  4. }

Subsequently, you can inject whatever handling code you wanted within your new if loop.

So what is an example of this type of code? It is very much up to your own design; you just have to use the AddMessage method that is provided by the FilterInfoBar class. There are very few methods that are available from this class, since it is mostly tiered around simply displaying this message to the user, but you can display even your own type of icon if you choose to. The AddMessage just takes a string value as a parameter.

For displaying information, you can use the WebPartConnection object to generate interesting data to display to the user, which can be generic to the connection if you just want to create one InfoBar generic helper class to use across a variety of projects. For example, you can use properties such as the ProviderConnectionPoint and ConsumerConnectionPoint classes in order to get valuable information about the connection that you are specifying using the InterfaceType property, or if you are simply looking to display basic information such as the name of the connection, you can just use the WebPartConnection.Consumer.DisplayTitle or WebPartConnection.Provider.DisplayTitle in order to structure the message to the user. To include this simply do a:

  1. AddMessage(Put Your Message In Here);

And your message will be rendered out!

Happy connecting!

Share

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>