Tag Archives: SharePoint

判断是否一个SharePoint Publishing页处于编辑模式

… 并且避免 ASP.NET 验证控件错误:

This page contains content or formatting that is not valid. You can find more information in the affected sections.

or

Input string was not in a correct format.

当创建一个WebPart来显示包含验证控件的表单时, ASP.NET 验证控件会阻止你签入和发布当前的Publishing页面.

解决方案:

  • Check if the web part is in edit or design mode and only add the validator if not:if (this.WebPartManager.DisplayMode != WebPartManager.EditDisplayMode &&
    this.WebPartManager.DisplayMode != WebPartManager.DesignDisplayMode)
    {
    // in display mode
    }

    This solution applies only if you have a single web part on the page, because you can only check if the current web part is in display/edit/design mode.

  • Another solution is using the EditModePanel. It allows you to add contols to the page in display or edit mode.
    For example:

    // add the EditBox to the page in edit mode
    EditModePanelpanel = newEditModePanel();
    TextBoxtextBox = newTextBox();

    panel.Controls.Add(textBox);
    panel.PageDisplayMode = PageDisplayMode.Edit;
    this.Controls.Add(panel);

    This solution didn’t work. Some replection shows me that the panel uses this function (which is obfuscated): public staticSPControlModeGetContextualFormModeFromPostedForm()
    This function comes from the internal class ConsoleUtilities.

  • The solution that worked for me was quite simple:

    // check if the form is in display mode
    bool inDisplayMode = SPContext.Current.FormContext.FormMode == SPControlMode.Display;

Well, good luck ;)

来源: http://blogs.microsoft.co.il/blogs/justguy/archive/2008/08/13/checking-if-a-publishing-page-is-in-edit-mode.aspx

How to get SharePoint 2007 SPList Forms Url

1
2
3
String formUrl = String.Format(CultureInfo.InvariantCulture, "{0}/{1}?id={2}",
SPContext.Current.Web.Url,
SPContext.Current.Web.Lists[ListName].Forms[ PAGETYPE.PAGE_DISPLAYFORM].Url, item.Id);

来源: http://www.myrocode.com/post/2009/03/20/How-get-SharePoint-2007-SpListItem-DispForm-Url.aspx

Export to Excel in SharePoint Application Page doesn’t work on second time

The cause for this behavior is that there is a flag (named _spFormOnSubmitCalled) in SharePoint which prevents double form submition. This flag is set when the form is submitted and clear when the response is received.

However when exporting the response is redirected and the page is not updated, thus the flag is not cleared and page’s postbacks are blocked.

In order to workaround this behavior you should manually clear the flag when exporting. This can be achieve, for example in export button’s client click function similar to the following:

MyExportButton.OnClientClick = “_spFormOnSubmitCalled = false;”

Setting the _spFormOnSubmitCalled to false is actually what MS Ajax is doing when an ajax request is made thus I suspect there should be not implication using such approach.

About the removing spFormOnSubmitWrapper function call, you may instead set _spSuppressFormOnSubmitWrapper variable to true, which can be done conditionally only where needed by outputting similar to the following script:

_spBodyOnLoadFunctionNames.push(“supressSubmitWraper”);
function supressSubmitWraper()
{
_spSuppressFormOnSubmitWrapper = true;
}

来源: http://www.telerik.com/community/forums/aspnet-ajax/grid/export-to-excel-in-sharepoint-application-page.aspx