Tony Testa posted on August 22, 2008 02:35

I ran across this link and thought I would share it with everyone.  I recall a ways back when I was just coming up to speed with SharePoint 2007, I really couldn't figure out which is the "best practice", .dwp web part files or .webpart files.  If you look in the web part gallery, you'll see a mix of both which made it even more difficult to figure it out.  Over at DotNetMafia, Corey Roth was nice enough to write a post telling you what each one does, and how .webpart is the latest version and is the one you should be using. 

Check out the post here


Today I ran into a bit of an issue in a SharePoint server farm environment where I added a web part to a page, but for the life of me I couldn't delete it.  I clicked the 'X' button, I tried to edit properties, I tried to delete from the edit pull down menu, but nada!  I tried from the load balanced URL and from the Index Server but no dice.  I did a quick google search and hit this helpful link,

http://www.sharepointblogs.com/nrdev/archive/2007/02/08/tip-easily-get-to-the-webpart-maintenance-page-for-any-sharepoint-site-url.aspx

Basically by adding "Contents=1" as a query string variable to any page, you'll go directly to the web part maintenance page for that page.

Ex. http://{site url}/pagewithproblemwebpart.aspx?contents=1 will take you to the maintenance page.

 

Update 7/7/2008

The url above will actually redirect you to the following url. 

Ex. http://{site url}/_layouts/1033/spcontnt.aspx?&url=pagewithproblemwebpart.aspx

 

Between the two url's I provided you should be able to deal with problem web parts and get back to a working page with little downtime.


I've spoken about this a few times in my presentations on the topic, but I don't think I ever blogged about it.  Basically to get ASP.NET AJAX to fully with with SharePoint 2007, you need to include some Javascript "fix" code which allows the ASP.NET AJAX to function properly. 

According to Microsoft, the reason for this code is the following "For ASP.NET controls that use the JavaScript _doPostBack() function to commit changes, a regular full-page postback event may occur even when the Web Part is inside an UpdatePanel control. Windows SharePoint Services 3.0 and ASP.NET AJAX cache certain form actions, which can cause a conflict between SharePoint and ASP.NET AJAX. To change this behavior, you must add code to scripts that are running in Windows SharePoint Services 3.0"

Below is the code you'll need to include in your Web Parts.

private void EnsurePanelFix()
{
   if (this.Page.Form != null)
   {
     String fixupScript = @"_spBodyOnLoadFunctionNames.push(""_initFormActionAjax"");
     function _initFormActionAjax()
     {
       if (_spEscapedFormAction == document.forms[0].action)
       {
         document.forms[0]._initialAction = 
         document.forms[0].action;
       }
     }
     var RestoreToOriginalFormActionCore = RestoreToOriginalFormAction;
     RestoreToOriginalFormAction = function()
     {
       if (_spOriginalFormAction != null)
       {
         RestoreToOriginalFormActionCore();
         document.forms[0]._initialAction = document.forms[0].action;
       }
     }";
   ScriptManager.RegisterStartupScript(this, 
     typeof(YOUR_WEBPART), "UpdatePanelFixup", 
     fixupScript, true);
   }
}
 
This code comes straight from Microsoft and you find it at http://msdn2.microsoft.com/en-us/library/bb861877.aspx
I've successfully been using the following code in my web parts without issue (for the life of me, I can't remember where I found it).
 
private void EnsureUpdatePanelFixups()
{
    if (this.Page.Form != null)
    {
        string formOnSubmitAtt = this.Page.Form.Attributes["onsubmit"];
 
        if (formOnSubmitAtt == "return _spFormOnSubmitWrapper();")
        {
            this.Page.Form.Attributes["onsubmit"] = "_spFormOnSubmitWrapper();";
        }
    }
    ScriptManager.RegisterStartupScript(this, typeof(Demo01SimpleWebPart), "UpdatePanelFixup", "_spOriginalFormAction = document.forms[0].action; _spSuppressFormOnSubmitWrapper=true;", true);
}
So the choice is yours as to which one to use. I've been sticking with the one I've found and have tested pretty thoroughly, but I'd like to think that the MS way is probably more "supported".

Posted in: Sharepoint  Tags: , ,

If anyone is in the VA Beach area on Feb 21st, stop by the Hampton Roads UG meeting.  I'll be presenting about how to use AJAX within your SharePoint Web Parts.  I presented on the same topic back at the Philly.Net Jan 2008 Code Camp and I think it went over really well, and one of the attendees runs the Hampton Roads UG, hence why I am presenting down there. 

Luckily for the attendees on thursday, I have updated the material to provide more "real world" examples, as well as some alternatives to using just using the straight MS ASP.NET AJAX framework to do AJAX.  I'll be including a few examples using jQuery, as well as the ICallbackHandler to do lightweight AJAX.  After attending Todd Bleekers' presentation on the same topic (I still feel mine is better of course!), he did turn me onto the ICallbackHandler idea.  Basically, it is a lightweight way to do AJAX style calls from your Web Parts, but as with everything AJAX related, it is to be used with caution. 

What I really want attendees to walk away with from this presentation, if they walk away with nothing else, is that SharePoint really is an "application platform" that you can develop on.  You can develop your apps using cutting edge technologies like AJAX and LINQ (my next upcoming presentation) for example, for those pieces of the app that need it.  But for the majority of your app, that 80% as they say, you can leverage what SharePoint comes with out of the box to achieve that 80%, and then use the other cutting edge technologies on that 20% of your app that really needs it.


Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2017 Tony Testa's World