Setting and Retrieving FormControl properties in code

Tony Feltham asked on July 12, 2018 15:20

I am trying to create my first custom form control that I can add into a webform in an ascx file

All is going OK but I dont know how to access the properties of the form control in code so that I can dynamically change the behaviour.

I have a form control which I defined a field called "UploadType".

In a webpart I have registered my new form control and have several instances of it within the webpart and all is displayed OK.

<%@ Register Src="~/CMSFormControls/KBC/OnboardingUploadControl.ascx" TagName="OnboardingUploader" TagPrefix="cms" %>

<cms:OnboardingUploader ID="driversLicenceUpload" UploadType="DRIVING_LICENSE" runat="server" />

<cms:OnboardingUploader ID="passportUpload" UploadType="PASSPORT" runat="server" />

<cms:OnboardingUploader ID="billUpload" UploadType="BILL" runat="server" />

<cms:OnboardingUploader ID="otherUpload" UploadType="OTHER" runat="server" />

I have set the UploadType of the control but now want to access the property within the code. The below code never finds the value of UploadType.

string uploadType = ValidationHelper.GetString(GetValue("UploadType"), "");

Should I be using another accessor function or am I looking in the wrong collection?

Also is it possible to set the value of the UploadType in code i.e driversLicenceUpload.UploadType = "DRIVING_LICENSE"; as this is not acceptable either

Many Thanks Tony

Recent Answers


vasu yerramsetti answered on July 12, 2018 15:55

@Tony,

Try this:

E.g: string controlType=driversLicenceUpload.UploadType;

E.g: string controlType=passportUpload.UploadType

Based on return value you can implement your logic.

0 votesVote for this answer Mark as a Correct answer

Tony Feltham answered on July 13, 2018 10:10

@Vasu

Thank you That works if I add the property manually in the code within the ascx file.

public string UploadType ;

<cms:OnboardingUploader ID="driversLicenceUpload" UploadType="DRIVING_LICENSE" runat="server" />

But if I add the property within a form builder using a drop down I cant retrieve the value set

public string UploadType
{
    get
    {
        return ValidationHelper.GetString(GetValue("UploadType"), "");
    }
}
0 votesVote for this answer Mark as a Correct answer

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