How to load a record into cms:UIForm

Alex Golebiewski asked on January 14, 2015 23:45

I'm using a CMS:UIForm in a web part to show an alternate form on a page. It works when the form is for a new entry but I'm unable to get it to load the record back in on another page using the ItemID for that record? Any help is appreciated.

Correct Answer

Alex Golebiewski answered on January 15, 2015 18:35

Ok here is the solution that worked for me.

On init I get the info object and set it to the EditedObject and then I reload the form data Form.ReloadData()

Then in the OnOnCreate method of the form I set the ObjectType, AlternativeFormName etc of the form.

1 votesVote for this answer Unmark Correct answer

Recent Answers

Virgil Carroll answered on January 14, 2015 23:56

You have to override the control load event In code behind and bind the ID to the form and put into edit mode vs. new mode.

Check out these two links:

0 votesVote for this answer Mark as a Correct answer

Alex Golebiewski answered on January 15, 2015 00:01

Can you show me an example? I'm not quite following.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on January 15, 2015 04:10

You should be able to:

  • set the form's ObjectType to the class name you're working with (cms.article)
  • set the form's AlternativeFormName to the full class name of the alt form (cms.article.myaltform)
  • set the form's Data property to the value you retrieve from looking up the ID of the object that was created. The Data property is a Base.IDataContainer object. If you are able to get the EditedObject that would work as well.
1 votesVote for this answer Mark as a Correct answer

Virgil Carroll answered on January 15, 2015 20:41

Thanks Brendan, I have not been able to get back to this. So 'What he said'

Wish these forums would keep us updated on comments

0 votesVote for this answer Mark as a Correct answer

Delford Chaffin answered on January 28, 2015 16:37

I'm having a related issue, so I hope you don't mind me hopping in here where it seems my answer may already be on the horizon.

I'm creating a custom module to manage users in a complex set up and remove a lot of the noise around the standard user management tools and make this a little easier for this particular client.

I have a module page with a UIForm tag:

<cms:UIForm ID="userForm" runat="server" AlternativeFormName="member_edit" ObjectType="cms.user" />

In Page_Load, I have the following:

userForm.Mode = FormModeEnum.Update;
userInfo = UserInfoProvider.GetUserInfo(memberId);
// userForm.Data = userInfo;
// userForm.EditedObject = userInfo;
// userForm.DataBind();
// userForm.FieldEditingControls["UserName"].Enabled = false;

When I hit the Save button with the above code, I get:

"The object with code name '_test' already exists."

If I un-comment that last line and disable the "UserName" field, I get:

"The RedirectUrlAfterCreate property must be set for creating of the new objects."

If I comment out the LoadData() command and try setting either the .Data or .EditedObject properties and call DataBind(), it doesn't actually load anything in.

What am I missing?

BTW - Also, in Page_Load, I have this form determining if this is a new user and setting Mode = Insert and setting the RedirectUrlAfterCreate and it seems to work fine.


0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.