Kentico & CMSForm: Load a different form after page load?

343 views Asked by At

Using Kentico 7, I have a cms form on the aspx page like so:

<cms:CMSForm runat="server" ID="cmsFormCreate"
    FormMode="Insert" ShowOkButton="false"
    ParentNodeID='<%# documentsFolderNodeID %>'
/>

On the backend, I'm setting the form's parent node id (so I have a base location to save to which I will change later.

I get the form/document name by calling

CMS.SettingsProvider.DataClassInfoProvider.GetClasses("*", "className LIKE '%MyDocument.%'", "", Integer.MaxValue).Tables(0).Rows

That returns a dataset which I negotiate for the document name, class id (if I ever need it) and so forth.

I want to change the form that is loaded on postback. That is to say that I have several document types in the CMS Site Manager and I want to swap between them. I want to display one on page load (this works fine). However, when I fire the mechanism to change the form which is displayed (dropdown list OnSelectedIndexChanged), it fails to load the new form.

Private Sub PopulateCMSForm(ByRef targetForm As CMS.FormControls.CMSForm, sourceDDL As ListItem)       
    targetForm.FormName = sourceDDL.Value
    'targetForm.LoadForm() 'same results with or without this
End Sub

I have verified that the form I expect shows up correctly by hard coding the form name (Document type code name) and the form will display just fine the first time the page loads.

How do I manage to change the empty/blank document type that the CMS Form object is loading on post-back?

1

There are 1 answers

3
Plaz On

try something like this:

Private Sub PopulateCMSForm(ByRef targetForm As CMS.FormControls.CMSForm, sourceDDL As ListItem)       
    targetForm.FormName = sourceDDL.Value
    targetForm.LoadForm(True) 
End Sub

True value as an argument of the method LoadForm should force reload of the form.