Archive

Archive for the ‘SharePoint’ Category

An error was encountered while retrieving the user profile.

March 16, 2012 Leave a comment

It is because the process cannt found the user profile .

You can try to solve it by following steps

  • Open Central Administrator-→Security-→General Security,copy user name from Configure service accounts
  • Open Central Administrator-→Application Management →Service Application→Manage Service Applications.
  • Click User Profile Service from the page you have opened at step2 , and select Manage User Profile from People
  • You can search the user profile by user name which you have copied at step1 ,
  • Click New Profile,create a new profile for your user name(at step1).

 

Advertisements
Categories: SharePoint

Can’t post back anything after file download in sharepoint!

March 16, 2012 Leave a comment

I have met this problem in my sharepoint project.

Here is my understanding and my final solution.

1, Sharepoint registers two additional javascript methods on Body Onload Event and Form Submit Event like below.


<BODY scroll="yes" onload="javascript:if (typeof(_spBodyOnLoadWrapper) != 'undefined') _spBodyOnLoadWrapper();">
<form name="aspnetForm" method="post" action="ShoppingList.aspx" onsubmit="javascript:return WebForm_OnSubmit();" id="aspnetForm">

And these methods are declared in the init.js file ,

function _spBodyOnLoadWrapper()
{
......
_spFormOnSubmitCalled=false;
.....
}

 

function WebForm_OnSubmit() {
......
return _spFormOnSubmitWrapper();
......
}

 

function _spFormOnSubmitWrapper()
{
if (_spSuppressFormOnSubmitWrapper)
{
return true;
}
if (_spFormOnSubmitCalled)
{
return false;
}
if (typeof(_spFormOnSubmit)=="function")
{
var retval=_spFormOnSubmit();
var testval=false;
if (typeof(retval)==typeof(testval) && retval==testval)
{
return false;
}
}
RestoreToOriginalFormAction();
_spFormOnSubmitCalled=true;
return true;
}

From the above source code we can know
 ■ When the body onload event be fired (The entire page be loaded and rendered) sharepoint will set the _spFormOnSubmitCalled variable to false. 
 ■ When the form be submitted(Page Control Events be raised )

  •    If _spFormOnSubmitCalled variable is ture,  stop submit.
  •    If _spFormOnSubmitCalled variable is false, submit and set it to true.

2, ASP.NET Page Life Cycle

From MSDN :  http://msdn.microsoft.com/en-us/library/ms178472.aspx

We can learn the order Page Load -> Control Event -> Page Render  .
After we press the download button , we will use the Response.End() in it’s event which would absolutely stop the page-lifecycle execution , so the page render event would never be fired.

3, Conclusion

Because we have called the Response.End() internally which ends the page execution ,  the body onload event would never be fired.
The _spFormOnSubmitCalled variable is always true , so we can’t post back anything after.

4, Solution

We just need to set the _spFormOnSubmitCalled variable to false on the download button by javascript.
Source code is like bellow.

var btn = new Button();
btn.OnClientClick = "_spFormOnSubmitCalled = false; ";
Categories: SharePoint