Form controls
List of examples:
- Creating a new form control
- Updating an existing form control
- Updating multiple form controls
- Deleting a form control
Creating a new form control
// Creates a new form control object
FormUserControlInfo newControl = new FormUserControlInfo();
// Sets the form control properties
newControl.UserControlDisplayName = "New control";
newControl.UserControlCodeName = "NewControl";
newControl.UserControlFileName = "~/CMSFormControls/Basic/TextBoxControl.ascx";
newControl.UserControlType = FormUserControlTypeEnum.Input;
newControl.UserControlForText = true;
// Saves the form control to the database
FormUserControlInfoProvider.SetFormUserControlInfo(newControl);
Updating an existing form control
// Gets the form control
FormUserControlInfo updateControl = FormUserControlInfoProvider.GetFormUserControlInfo("NewControl");
if (updateControl != null)
{
// Updates the form control properties
updateControl.UserControlDisplayName = updateControl.UserControlDisplayName.ToLower();
// Saves the changes to the database
FormUserControlInfoProvider.SetFormUserControlInfo(updateControl);
}
Updating multiple form controls
// Prepares a where condition for loading form controls whose code name starts with 'NewControl'
string where = "UserControlCodeName LIKE N'NewControl%'";
// Loads the form controls into a strongly typed data set
InfoDataSet<FormUserControlInfo> formControls = FormUserControlInfoProvider.GetFormUserControls(where, null);
// Loops through the form controls
foreach (FormUserControlInfo modifyControl in formControls)
{
// Updates the properties of the form control
modifyControl.UserControlDisplayName = modifyControl.UserControlDisplayName.ToUpper();
// Saves the changes to the database
FormUserControlInfoProvider.SetFormUserControlInfo(modifyControl);
}
Deleting a form control
// Gets the form control
FormUserControlInfo deleteControl = FormUserControlInfoProvider.GetFormUserControlInfo("NewControl");
// Deletes the form control
FormUserControlInfoProvider.DeleteFormUserControlInfo(deleteControl);