« Example: Call Private Method w/ Reflection | Main | SmartPart and AjaxBasePart get Together »

02/20/2007

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a010534b16473970c011168f04d4f970c

Listed below are links to weblogs that reference AjaxBasePart: Easy ASP.NET 2.0 AJAX Extensions 1.0 and Office SharePoint Server 2007:

Comments

Feed You can follow this conversation by subscribing to the comment feed for this post.

This is great work! One question - Are there any dependencies on MOSS or will this work with WSS as well. Thanks.

It should work fine with WSSv3. I am pretty sure there are no dependencies, but I have not personally tested it. Please post a followup comment if it works so others can benefit.

Thanks!

Dear Eric,

I get the following error:

'Microsoft.SharePoint.Utilities.SPUtility' does not contain a definition for 'TransferToErrorPage'

Could you please help?

Lilia,

Interesting, are you using MOSS or just WSSv3? I haven't run into this. One way to avoid that error would be to remove the functionality described in the "Bonus" section.

Delete from the AjaxBasePart.cs file the following items:

RegisterError method
CreateChildControls override
_ErrorContainer and _ValidationGroupId private variables


Let me know if that works for you.

Thanks!

Hey Eric! Rember me? I used to work at VastNetworks with Derek B. Anyhow I was surfin the WSS blogs one day and found you on here. Its kind of funny that we are both SharePoint Devs! I've been running a blog too (sharethispoint.com), its pretty fun. Well I just wanted to say hi and let you know that this Ajax base part you did is pretty sweet. I've built a sample project that uses it to display a SPGridView in an UpdatePanel. Heres the link if you wanna check it out..

http://sharethispoint.com/archive/2007/02/28/Using-a-SPGridView-inside-an-ASP.net-Ajax-UpdatePanel.aspx

Hit me up on msn some time.
Take care,
Mark Collins

Mark,

Good to hear from you, great example on your blog. Glad you are finding the AjaxBasePart useful.

I definately remember when you worked at VastNETWORKS. I also remember paintball and the Mountain Dew statue. Good times :)

This is great! Works like a charm for an update panel. However, I'm not as successful in getting the Ajax Timer working (inside or outside an update panel). On its tick event it is throwing an, "Object reference not set to an instance of an object." exception. I've traced this back to a javascript error. I hypothisize that MOSS's own javascript is interfearing w/ the timer's javascript. Do you have any suggestions? Thanks!

The timer control works fine for me. That was actually the main reason for doing this work... so that I could create an UpdatePanel that is triggered by a Timer.

One of the main things that you will need to remember is to set your controls ID property.

Here is a small snippet from a sample I have, sorry that I don't have time to package it up for you (below class is incomplete):

public class TestWP : AjaxBasePart
{
private Timer tmr_RefreshTime;
private UpdatePanel up_ServerTime;

private UpdatePanel up_Grid;

protected override void CreateChildControls()
{
base.CreateChildControls();

tmr_RefreshTime = new Timer();
tmr_RefreshTime.ID = "tmr_RefreshTime";
tmr_RefreshTime.Enabled = true;
tmr_RefreshTime.Interval = 2500;

AsyncPostBackTrigger astrig_tmr_RefreshTime = new AsyncPostBackTrigger();
astrig_tmr_RefreshTime.ControlID = "tmr_RefreshTime";

up_ServerTime = new UpdatePanel();
up_ServerTime.ID = "up_ServerTime";
up_ServerTime.UpdateMode = UpdatePanelUpdateMode.Conditional;
up_ServerTime.ContentTemplate = new ServerTimeUpdateTemplate();
up_ServerTime.Triggers.Add(astrig_tmr_RefreshTime);
up_ServerTime.Load += new EventHandler(up_ServerTime_Load);

this.Controls.Add(tmr_RefreshTime);
this.Controls.Add(up_ServerTime);

up_Grid = new UpdatePanel();
up_Grid.ID = "up_Grid";
up_Grid.ChildrenAsTriggers = true;
up_Grid.UpdateMode = UpdatePanelUpdateMode.Conditional;
up_Grid.ContentTemplate = new GridUpdateTemplate();
up_Grid.Load += new EventHandler(up_Grid_Load);

this.Controls.Add(up_Grid);
}
}

Thanks Eric. This helped a lot. I did have to change one line:
astrig_tmr_RefreshTime.ControlID = "tmr_RefreshTime";
because "tmr_RefreshTime" wasn't found in the client script to:
astrig_tmr_RefreshTime.ControlID = tmr_RefreshTime.ClientID;

Thanks again! Justin

Justin, thanks for following up so that others can benefit from your learning. Glad you were able to get it working.

Could this be written as a normal asp.net web part instead of a sharepoint web part?

kman,
There is some code in the AjaxBasePart that is specific to a MOSS implementation (around enabling postbacks).

The idea of a web part that uses a ScriptManager that exist on the page or creates one if none exists should be portable to normal ASP.NET web parts. I would recommend other methods though... such as ensuring that you don't have to dynamically place a ScriptManager.

Of course, I read this article after I had just finished modifying 95% of my MasterPages in SharePoint.

I already had created a base class that did most of this functionality. I added a virtual property to set the padding on the control, and a few other things too

Eric,
Tried out your AjaxBasePart with a SP GridView Web Part and worked fine when inserting WebPart in standard Sharepoint administrative default page. However, when inserting it in an SP Designer aspx page in a WebPartPages:WebPartZone, it gave me the following error: "Cannot create an object of type 'System.Web.UI.ScriptManager' from its string representation for the 'AjaxManager property'". When inserting another standard WebPart into the same page there was no problem and the control worked okay. Have you seen this before and do you have any suggestions?

Thanks,
Frank

I was able to get everything wired up no problems into an existing SharePoint site. However, when I come to use an AJAX control (ie. calendar) into one of the pages, I receive the following error:

System.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. ).

With the following stack trace:
The Controls collection cannot be modified because the control contains code blocks (i.e. ).]
System.Web.UI.ControlCollection.Add(Control child) +2114095
AjaxControlToolkit.ScriptObjectBuilder.RegisterCssReferences(Control control) +371
AjaxControlToolkit.ExtenderControlBase.OnPreRender(EventArgs e) +163
System.Web.UI.Control.PreRenderRecursiveInternal() +77
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1360


Any ideas how to fix this problem?

I'm trying to use the AjaxControlToolkit in a MOSS 2007 web part and it almost works... I'm using the tabcontrol and even though I've also tried using the class you provided I get the same results. My tabs are cut off on each tab panel on the bottom. I can't figure out why. Any thoughts would be helpful. Below is my code:

//snipped by Admin

Frank, that may be a problem with dropping an AjaxBasePart based control on a page using SharePoint Designer. It should be fairly easy to tweak the AjaxBasePart class to be aware of when it is being rendered to the page in design mode.

If you do and have an opportunity to post your modification on the internet somewhere or send it to me so that I can post it for you that would be great.

Thanks!

Steve, I have not used the tab control within SharePoint using the AjaxBasePart but I have used other controls in the tool kit. My gut feeling is that you are having problems with styles being applied correctly (CSS).

Ammar, I have not seen that error before. Let me know if you identify the problem and find a solution.

Hi,
I have been trying to use this with sharepoint and webparts. Unfortunately, the ajaxbasepart doesnt seem to add the scriptmanager - during OnInit the Page.Form seems to be null.
i have alsoi been trying to use updatepanel with timer, would this even work? (i added scriptmanager to the masterpage to test this, dident quite work).

hi...i copied the AjaxBasePart class to my solution ..i am getting the error "the type or namespace name "ScriptManager" could not be found"...pls tell me what is the solution

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment