Unanswered FormField - Operation is not valid due to the current state of the object.

  • Thursday, August 16, 2007 8:59 AM
     
     

    Hi everyone,

     

    I am currently creating a custom application page which is used to modify some list items.

     

    Basically, each site will have some "site meta data" stored, which I want to keep in a list at the top-level site collection.

     

    I am trying to use Microsoft.SharePoint.WebControl.FormField controls in "ControlMode.Edit" mode for the editing.

     

    Now, if I access this page from the top-level (where the list is stored) then it works perfectly.

     

    If I try to access the page from a sub-site then I get the error message:

     

    Operation is not valid due to the current state of the object.

     

    Now .. I used to think that this was due to the rendering context (as it retrieves the FormField.Web property from the SPContext object stored in the FormField.RenderingContext property) but setting that hasn't worked (unless I'm doing it wrong)

     

    Here is my code:

    (other sections removed for clarity)

     

    Code Snippet

    // get the top-level Web Site

    SPWeb web = SPContext.Current.Site.RootWeb;

    // generate a Context object for that web site

    SPContext context = SPContext.GetContext(web);

     

    // get the list that stores the Site Data

    SPList list = web.Lists["SiteDataList"];

     

    // for now, just grab the first item, to make sure it works

    SPListItem = list.Items[0];

     

    // create a new form field object

    FormField fldTitle = new FormField();

    // populate the context / list / item values for binding

    fldTitle.RenderingContext = context;

    fldTitle.ListID = list.ID;

    fldTitle.ItemID = item.ID;

    // set the Field and control mode

    fldTitle.FieldName = "Title";

    fldTitle.ControlMode = SPControlModes.Edit;

     

    // add control to my page

    this.Controls.Add(fldTitle);

     

     

     

    Anyone have any ideas ???

     

    Summary of details:

    • List is stored a RootWeb level
    • Application page works perfectly from Root Web level
    • Application page throws error message when accessed from sub-site.

All Replies

  • Thursday, August 16, 2007 2:58 PM
     
     

    Hi ..

     

    I've now resorted to replacing all of the FormField controls with standard ASP.Net controls (TextBox / DropDownList).

    I don't mind this for the text fields, but for the Lookup columns and User columns this is a right pain the backside.

    (especially when it comes to custom rolling my own SPFieldLookupValue objects, not to mention the Active Directory searching features?)

     

    Does anyone else have any suggestions?

     

    - MK

  • Friday, December 14, 2007 2:31 PM
     
     
    Hi, I get the same error, did you find out a solution?