Finding All Controls on Page in Asp.net

 

private void ListControlCollections()
{
ArrayList controlList = new ArrayList();
AddControls(Page.Controls, controlList);

foreach (string str in controlList)
{
// Response.Write(str + “<br/>”);
cbx_control.Items.Add(str);
}
Response.Write(“Total Controls:” + controlList.Count);
}
private void AddControls(ControlCollection page, ArrayList controlList)
{
foreach (Control c in page)
{
if (c.ID != null)
{
controlList.Add(c.ID);
}

if (c.HasControls())
{
AddControls(c.Controls, controlList);
}
}
}

private void KapaliControl(Control ctrl)
{
foreach (Control c in ctrl.Controls)
{
KapaliControl(c);
if (c is ASPxTextBox)
{
((ASPxTextBox)(c)).Enabled = false;
}
else if (c is ASPxComboBox)
{
((ASPxComboBox)(c)).Enabled = false;
}
else if (c is ASPxEdit)
{
((ASPxEdit)(c)).Enabled = false;
}
}
}
private void AcikKontrol(Control ctrl)
{
foreach (Control c in ctrl.Controls)
{
AcikKontrol(c);
if (c is ASPxTextBox)
{
((ASPxTextBox)(c)).Enabled = true;
}
else if (c is ASPxComboBox)
{
((ASPxComboBox)(c)).Enabled = true;
}
else if (c is ASPxEdit)
{
((ASPxEdit)(c)).Enabled = true;
}
}
}
private void TumunuTemizle(Control ctrl)
{
foreach (Control c in ctrl.Controls)
{
TumunuTemizle(c);
if (c is ASPxTextBox)
{
((ASPxTextBox)(c)).Text = “”;
}
else if (c is ASPxComboBox)
{
((ASPxComboBox)(c)).SelectedIndex = 0;
}
else if (c is ASPxDateEdit)
{
((ASPxDateEdit)(c)).Text = “”;
}
else if (c is ASPxButtonEdit)
{
((ASPxButtonEdit)(c)).Text = “”;
}
}
}

TumunuTemizle(this.Page);

KapaliControl(this.Page);

AcikKontrol(this.Page);

KategorilerGenel

Bir Cevap Yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir