SharePoint Field on List Form

1.SharePoint:FieldLabel

  a.Show display name of list field.

     Example:<SharePoint:FieldLabel ID="Fldlab_CustomerName" runat="server" FieldName="CustomerName" ControlMode="New"></SharePoint:FieldLabel>

2.SharePoint:FormField

  a.input/edit/display value of list field.

    Example:<SharePoint:FormField runat="server" ID="fld_CustomerName" ControlMode="New" FieldName="CustomerName" CssClass="width100"></SharePoint:FormField>
3.SharePoint:FieldDescription

  a.Show description of list field.

  Example:<SharePoint:FieldDescription runat="server" id="fldDes_CustomerName" FieldName="CustomerName" ControlMode="New"/>

4.SharePoint:SaveButton

  a.Submit list item to list.

  Example:<SharePoint:SaveButton runat="server" ControlMode="New" ID="savebutton" />

5.SharePoint:GoBackButton

  a.Cancel and close the page  and return to list view or return url.

  Example:<SharePoint:GoBackButton runat="server" ControlMode="New" ID="gobackbutton" />

6.Initialize sharepoint field by Oninit event.

  <SharePoint:FormField runat="server" ID="fld_Body" ControlMode="Edit" FieldName="Body" OnInit="ListFormField_OnInit"></SharePoint:FormField>

  protected void ListFormField_OnInit(object sender, EventArgs e)
        {
            //SPListItem currentTaskItem = SPContext.Current.ListItem;
            Guid listGuid = new Guid(Request["TaskList"]);
            Int32 taskItemId =Convert.ToInt32(Request["TaskId"]);
            FormField currentField = sender as FormField;
            currentField.ListId = listGuid;
            // Get the SPContext object based on the current web and specified list id and item id.
            SPContext context = SPContext.GetContext(HttpContext.Current, taskItemId < 0 ? 0 : taskItemId, listGuid, SPContext.Current.Web);
            currentField.RenderContext = context;
            currentField.ItemContext = context;
            currentField.ItemId = taskItemId;
        }

7.Override SaveButton Event For List Form.

  //In your aspx page a control like this should be available
  <sharepoint:savebutton   runat="server" ControlMode="New"  ID="savebutton" ></sharepoint:savebutton>

  //Override Save Button in the init method
  protected override void OnInit(EventArgs e)
  {
    //In the init method you overrite the event handler for saving with your save button action
    base.OnInit(e);
    SPContext.Current.FormContext.OnSaveHandler += new EventHandler(mySaveHandler);
  }

  private void SaveAndPerformAddtionalTask(object sender, EventArgs e)
  {
    bool isSaveSuccessful = false;

    SaveButton btnSave = sender as SaveButton;
    //you can validate the page if you like
    Page.Validate();
    if (Page.IsValid)
    {
        // Do pre save tasks
        isSaveSuccessful = SaveButton.SaveItem(btnSave.ItemContext, false, "");
        if (isSaveSuccessful)
        {
          //Do post save tasks
       }

    }
  }

posted @ 2017-09-05 17:39  【上海】Peter  阅读(219)  评论(0)    收藏  举报