What I am trying to Do is accessing Page Controls at Page_Load, and make a database query, and make controls visible or not visible.
Here is the Code
foreach (Control thiscontrol in ContentPlaceHolderBody.Controls) {
try
{
if (thiscontrol.ID.Contains("TextBox") || thiscontrol.ID.Contains("Label"))
{
string dummy = thiscontrol.ID;
bool IsValid = db.Roles.Any(a => a.controlName == dummy);
if (IsValid == false)
thiscontrol.Visible = false;
}
else if (thiscontrol.ID.Contains("UpdatePanel"))
{
foreach (Control UPcontrols in ((UpdatePanel)thiscontrol).ContentTemplateContainer.Controls)
{
if (UPcontrols.ID.Contains("TextBox") || UPcontrols.ID.Contains("DropDownList"))
{
bool UPIsValid = db.Roles.Any(a => a.controlName == UPcontrols.ID);
if (UPIsValid == false)
UPcontrols.Visible = false;
}
}
}
}
catch { }
}
My Problem is with the UPcontrols ! IT should retrieve the controls within the UpdatePanel, but the thing is it doesnt do its Job except in the Debug Mode !!! ... When I add a breakpoint everything is OK ! ... but when I run the web application it doesnt find any components within the UpdatePanel ....
PLease help me ... It is a very important case...
Thanks !