I have a strange issue where controls on a webpage (text/checkbox/radio/dropdown) are displayed either in read-only mode or edit mode (depending on the choice of display or edit on a previous page). All controls are usercontrols which contain the relevant
intrinsic web control + a literal control for the "display" version and the code simply swaps the visibility of each depending on whether "display" or "edit" has been chosen. So for example, if a checkbox is ticked, edit gives
you the checkbox and display gives you the literal control with "YES" in it.
The website has a function which loops through all the controls on a page and sets the version by the usercontrol TYPE, not individually named controls, as follows :
public static void setRenderMode(WebControl pnl, int renderMode)
{
foreach (Control c in pnl.Controls)
{
string typeString = c.GetType().ToString();
if (typeString.ToLower().Contains("formcontrols_singlecontrols_lwrcalendarcontrol"))
{
FormControls_LWRCalendarControl ac = (FormControls_LWRCalendarControl)c;
ac.RenderMode = renderMode;
}
else if (typeString.ToLower().Contains("formcontrols_singlecontrols_lwrdropdowncontrol"))
{
FormControls_LWRDropDownControl ac = (FormControls_LWRDropDownControl)c;
ac.RenderMode = renderMode;
}
else if (typeString.ToLower().Contains("formcontrols_singlecontrols_lwrradiocontrol"))
{
FormControls_LWRRadioControl ac = (FormControls_LWRRadioControl)c;
ac.RenderMode = renderMode;
}
else if (typeString.ToLower().Contains("formcontrols_singlecontrols_lwrtextcontrol"))
{
FormControls_LWRTextControl ac = (FormControls_LWRTextControl)c;
ac.RenderMode = renderMode;
}
else if (typeString.ToLower().Contains("formcontrols_singlecontrols_lwrfckcontrol"))
{
FormControls_LWRFckControl ac = (FormControls_LWRFckControl)c;
ac.RenderMode = renderMode;
}
else if (typeString.ToLower().Contains("formcontrols_singlecontrols_lwrcheckboxcontrol"))
{
FormControls_LWRCheckBoxControl ac = (FormControls_LWRCheckBoxControl)c;
ac.RenderMode = renderMode;
}
else if (typeString.ToLower().Contains("formcontrols_agreggatecontrols_aggregate_dropdowncontrol"))
{
FormControls_AggregateControls_AggregateDropDownControl ac = (FormControls_AggregateControls_AggregateDropDownControl)c;
ac.RenderMode = renderMode;
}
else if (typeString.ToLower().Contains("system.web.ui.webcontrols.checkbox"))
{
CheckBox ac = (CheckBox)c;
ac.Enabled = renderMode == 0 ? true : false;
}
else if (typeString.ToLower().Contains("system.web.ui.webcontrols.radiobutton"))
{
RadioButton ac = (RadioButton)c;
ac.Enabled = renderMode == 0 ? true : false;
}
}
}
so far so good and works fine in other websites I have created previously.
you get the idea.....anyway in "display" mode, some controls are rendering as though in "edit" mode on the page, particularly the text ones for some reason. I would be inclined to think there was an error in my code if it were not for
the fact that SOME work but OTHERS don't ! The generic rendering of the controls means that it should be ALL CORRECT or ALL INCORRECT.
Now here's the rub...…
If I put a breakpoint on the first incorrectly displayed control, by name and step through right into the usercontrol which sets the visibility as described above, then continue running the code with no further breaks, the webpage then displays that control
correctly and does so forever afterwards, even though running the website with no breaks from the start, its displayed incorrectly ! GO FIGURE !!
If it was only a few controls I would just overlook the vagaries of Visual Studio for the sake of time and just do as described above but I have a couple of hundred controls which are wrong !
Please, if there is anyone out there who has found a similar issue or can proffer an explanation then I need your assistance, much appreciated.
P.S i'm using VS2015 Professional
Thank You