How access dynamic added controls from code behind

Ashish Rathore

I'm having a class which adds some controls into my web form. Now i need to access dynamically added controls by my class. Can any one tell me how can i access dynamically added controls from server side code.

Ashish Rathore

I've find a solution for problem.Looping through all controls.

public static IEnumerable<Control> GetControls(ControlCollection controlCollection)
{
    foreach (Control control in controlCollection)
    {
        yield return control;

        if (control.Controls == null || control.Controls.Count == 0)
            continue;

        foreach (var sub in GetControls(control.Controls))
        {
            yield return sub;
        }
    }
}

After creating IEnumerable list check for the Control's ID.

    foreach (Control c in ctr__)
    {
        if (c.ClientID == "dropUGrp")
        { 
           //Code goes here
           break;
        }
    }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I access my ViewModel from code behind

Xamarin Can't Access Controls on Code Behind

CheckBox CheckedChanged event added from code behind

How to prevent controls are added into a component derived from TCustomPanel?

WPF sending value to code behind from dynamic image?

Xamarin Forms - access controls in a list view from the parent page code-behind

How to access QML\QtQuick controls from PySide?

I am not able to access x:Name of controls in ListView in XAML and Code behind

how to access form controls from another class

How do I add an on click event to image button added from code behind

How to access code behind from Tablet/Phone template?

How to access a selected Boundfield value from a GridView in code-behind

Access DataTemplate controls in code behind

Dynamic added controls in JQuery

How to access a control templace in code behind?

XamDataGrid - how to access the fields from code behind

WebView not visible when added to content from code behind

How to access the selected item in a Droplist in Code Behind?

I cannot access Web Form controls on code-behind in Xamarin

How to access property defined in code-behind from markup in Web Forms User Control

How to access WPF controls from a background thread

How to access a DataContext, that has been specified in XAML, from within code-behind?

How can I access the images folder from code behind

How to access UI control from code-behind of ResourceDictionary

C# How get bitmap from dynamic <img> in code behind in .aspx

How to disable bootstrap controls from code behind

How to access an "<input type="text" from code behind in ASP NET

WPF bind to ancestor from UserControl that is added from code behind

How to get the value of an HTML element attribute that added from code behind?