0

When i am adding web part to page its page load call, Now problem is that it require some info on page load and it breaks. i do not want to execute my webpart page load code when i add it into a page. Please suggest.

0

Check the mode of the page in PageLoad method and perform the action depending on that. Example: In case of web part page

if (Microsoft.SharePoint.SPContext.Current.FormContext.FormMode == SPControlMode.Edit)
    {
        ltr.Text = "EditMode2";
    }
    else
    {
        ltr.Text = "ViewMode";
    }

If it is a publishing page:

if (Microsoft.SharePoint.SPContext.Current.FormContext.FormMode == SPControlMode.Display)
  {
   // your code to support display mode
  }
  else // Microsoft.SharePoint.SPContext.Current.FormContext.FormMode = SPControlMode.Edit
  {
   // your code to support edit mode
  }

Source: https://stackoverflow.com/questions/9478913/determine-display-mode-of-sharepoint-page

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.