SharePoint, AJAX UpdatePanel and SPWebPartManager woes

26 01 2010

If you are having trouble getting your AJAX UpdatePanel to update properly in a SharePoint page or Web Part then you have come to the right place. You may already be aware that to get an UpdatePanel working in SharePoint you need to add a an additional function to your code that alters the _spFormOnSubmitWrapper and the _spSuppressFormOnSubmitWrapper. See here for an example –

http://petesullivan.wordpress.com/2008/06/13/ajax-update-panels-and-sharepoint/

However!! If you are using a custom Master Page then watch out because there is another gotcha!

It seems that if the SPWebPartManager tag appears before the Form tag in your master page then your updatepanel will not update properly and most likely won’t display any content. This should be changed so the SPWebPartManager tag appears underneath the form tag, see below for an example –

Incorrect

<WebPartPages:SPWebPartManager ID="SPWebPartManager1" runat="server"/>   
<form id="Form1" runat="server" onsubmit="return _spFormOnSubmitWrapper();">

Correct

<form id="Form1" runat="server" onsubmit="return _spFormOnSubmitWrapper();">
<WebPartPages:SPWebPartManager ID="SPWebPartManager1" runat="server"/>

Hope this helps! 🙂

Advertisements




Creating Custom SharePoint Web Part Connections

25 01 2010

I created my first web part connection the other day and was surprised at how easy and effective it was. I thought I would walk through the process that is required to connect two custom web parts together.

In this brief tutorial I am not going to cover how to create a web part or how to deploy one. I will assume that you (the reader) already knows how to do this. All code in this tutorial will be written in C#.

1. To begin create yourself two web parts – one of these will be the ‘Provider’ and the other the ‘Consumer’. You can create these however you like either using the VseWSS extensions or perhaps in an empty class library project.

2. Create an interface similar to the one below –

 public interface IExampleProvider
 {
        String TestParam { get; }
  
 }

Inside this interface you should define any parameters that you wish to send to your ‘Consumer’ web part.

3. In your Provider web part ensure that it implements the interface you have just created –

 public class ProviderWebPart: WebPart, IGovernanceProvider
 {
 }

4. Next create a property that returns the interface and decorate it with the  ConnectionProvider attribute. The parameters of  are the display name and the real name (ID) of the connection.

 [ConnectionProvider(&quot;Test Parameter&quot;,&quot;ExampleID&quot;, AllowsMultipleConnections=true)]
 public IExampleProvider GetExampleProvider()
 {
    return this;
 }

5. Finally for the Provider web part you need to ensure that the parameter property from your interface is implemented –

protected string _TestParam = &quot;&quot;; 
public string TestParam 
{
 get { return _TestParam; } 
}

6. Now its time to setup the Consumer web part, in your consumer web part class define a method that will accept the interface as a parameter and decorate it with the ConnectionConsumer attribute.

private IExampleProvider exampleProvider;
[ConnectionConsumer(&quot;Site URL&quot;)]
public void RegisterProvider(IExampleProvider provider)
{
   this.exampleProvider = provider;
}

7. You can now retrieve the value/values that have been sent to the consumer web part by calling the properties of the exampleProvider. Note you should check if a connection has been made first by seeing if the exampleProvider is null.

string myParam = this.exampleProvider.TestParam;

8. Deploy your two web parts by whatever method you wish, when you add the web parts to the page and click the ‘edit’ dropdown you should see a new menu option called ‘Connections’. The menu will appear on both the provider and consumer web parts but you only need to configure one.

Consumer Web Part:

image

Provider Web Part:

image

9. You are finished!

I hope you enjoyed this brief tutorial into web part connections, if you have any questions then feel free to leave a comment!

Hope this helps 🙂





VseWSS 1.3 CTP March 09 – Still Buggy

15 10 2009
I’ve been developing a web part today and thought I would try the VseWSS extensions to see if they would get the job done quicker, I normally just create the Visual Studio solution myself and use WSPBuilder (http://www.codeplex.com/wspbuilder) to deploy it.

After I had built my web part I clicked to debug and was presented with the following error:

clip_image002_2

To get past this error I used the following two blog posts:

http://blogs.msdn.com/steve_fox/archive/2009/03/18/vsewss-1-3-post-install-configuration.aspx

http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2009/02/05/vsewss-1-3-ctp-feedback-and-feature-requests.aspx

It seems that the error is because the account running the application pool for VseWSS web application in IIS does not have the correct permissions. I was on a domain controller so simply gave the account domain admin permissions. This however did not fix the error and I ended up giving the account full control to the folder itself!

When I tried to deploy again I did not get the above error but now a different one (See screenshot below)! I cannot find any more details on this error and the folders specified in the error message do not even exist.  I think im going to go back to using WSPBuilder from now on as it seems the VseWSS extensions are still quite buggy.

Untitled

If anyone has any more details on the above error and how to fix it then please let me know 🙂