UIForm works in Insert Mode, but not Update

Delford Chaffin asked on January 28, 2015 19:54

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.LoadData(userInfo);
// 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.

Thanks!

Recent Answers


Virgil Carroll answered on January 28, 2015 22:35

Delford,

Are you doing this in a page, or did you inherit from the CMSAbstractWebPart class for the control? What is sounds like is your code is trying to do this after the form has already rendered.

I would go into the CMSWebParts directory and check out the form control and see the lifecycle of it. Typically the form set-up is done during the SetupControl() function (which gets called from the OnContentLoad). This happens pre-page render.

If you are not using the CMSAbstractWebPart and want to do this in a ASPX page, I would try moving your code to the Page_Init function, so you are settings these values pre-page render. I have not tried that, but I suspect that would help. In your instance I think you code is trying to override settings that already are set.

Hope that helps

  • Virgil
0 votesVote for this answer Mark as a Correct answer

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