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

huangapple go评论51阅读模式
英文:

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}  ",
                      modifiedFieldName, modifiedFieldName, isCheckedClause, itm.name);
            }
            else
            {
                sb.AppendFormat("<input type=\"checkbox\" id=\"{0}\" class=\"{1}\" name=\"{2}\" {3} />{4}  ",
                      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.

答案1

得分: 0

在代码库中实际上有:
MultipleCheckBoxes(多个复选框)

RO_MultipleCheckBoxes(只读多个复选框)
其中 RO_ 代表“只读”。

因此,我提出的问题实际上有点无意义,因为在 RO_MultipleCheckBoxes 存在的情况下,没有人会在那里放置指令标签。

此外,任何人在没有访问我们整个代码库的情况下都很难解决这个问题。

然而,我打算保留这个问题(暂时),因为它可能有助于其他人思考这些情况。

英文:

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.

huangapple
  • 本文由 发表于 2023年4月20日 03:47:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76058297.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定