Search code examples
javascriptasp.netuser-controls.net-4.8ascx

ascx User controls form is is not editable for some input data, so need to hide instructions if so


I am working from a legacy code base where there are forms with controls distributed in ascx files for an asp.net application.

The forms will load data from the database, and for some specific cases of loaded data the form is greyed out (not editable) including controls such as multiple checkboxes.

Example code is:

   <div>
   <p style="border-width:3px; border-style:solid; border-color:#0000FF; padding: 1em;"> Select all groups(s) that apply or select not applicable.</p>
   <%=OurInputHelpers.MultipleCheckBoxes(true, "Group", Model.GetIdsNamesList_SelectedGroups(), "Group", null)%>
   </div>

I am searching for the mechanism of how the edit-ability of the form is controlled and it is greyed out for certain input data.

The C# code-behind for MultipleCheckBoxes is as follows, but I don't think it will give much insight: [it is legacy code, so I don't get the credit for writing it]

   public static string MultipleCheckBoxes(bool requiredField, string modelFieldName, List<IdNameListItem> items, string label, string optionalCheckBoxClassName, bool eachOnSeparateLine = false)
    {
        // NOTE: the following prefaces are needed for javascript error processing to work:
        String inputFieldID = "inpt_" + modelFieldName;
        String labelFieldID = "lbl_" + modelFieldName;

        StringBuilder sb = new StringBuilder();

        // NOTE: for this type of ctl we have to surround it with a div tag, so that javascript error processing can apply a red border if need be
        sb.AppendFormat("<div id=\"{0}\">", inputFieldID);
    //    sb.Append("<span>");


        sb.Append(LabelTag(requiredField, null, label, labelFieldID));


        bool firstLine = true;
        foreach (IdNameListItem itm in items)
        {


            if (eachOnSeparateLine)
            {
                if (firstLine)
                {
                    firstLine = false;
                }
                else
                {
                    sb.Append("<br/>");
                }
            }
            string modifiedFieldName = "CheckBoxMulti_" + modelFieldName + "^" + itm.id.ToString();
            string isCheckedClause = (string)(itm.isSelected ? "checked=\"checked\" " : string.Empty);
            if (optionalCheckBoxClassName == null)
            {

                sb.AppendFormat("<input type=\"checkbox\" id=\"{0}\" name=\"{1}\" {2} />{3}&nbsp;&nbsp;",
                      modifiedFieldName, modifiedFieldName, isCheckedClause, itm.name);
            }
            else
            {
                sb.AppendFormat("<input type=\"checkbox\" id=\"{0}\" class=\"{1}\" name=\"{2}\" {3} />{4}&nbsp;&nbsp;",
                      modifiedFieldName, optionalCheckBoxClassName, modifiedFieldName, isCheckedClause, itm.name);
            }
        }
     //   sb.Append("<br/></span>");
        sb.Append("<br/>");
        sb.Append("</div>");
        return sb.ToString();

    }

However, I cannot find the exact mechanism for the controls being greyed out, so the posted code would only be partially helpful.

GOAL: I would like to conditionally hide instructions to the user when the controls (such as multiple-check-boxes) are greyed out.


Solution

  • There are actually within the codebase: MultipleCheckBoxes and RO_MultipleCheckBoxes where RO_ stands for "Read Only"

    Therefore, the question I asked was somewhat moot, as one just doesn't put the instruction tag where there are RO_MultipleCheckBoxes.

    Furthermore, it would be hard for anyone to solve this WITHOUT access to our entire codebase.

    However, I intend to leave this question up (for now) as it may help others in thinking about these situations.