locked
Iterating through Page Control Collection to find HtmlControls that are not running at server RRS feed

  • Question

  • User1550836914 posted

    I was trying to find get access to every control in a control collection within a page.  I found I had to take into account if the body was running at server or not also.

    foreach (Control control in this.Page.Controls)

    {

    //here for body tag runat server

    if (control is HtmlContainerControl)

    {

    if (control is HtmlControl)

    {

    ManageHTMLControl(control
    as HtmlControl);

    }

    foreach (Control innerControl in control.Controls)

    {

    if (innerControl is HtmlForm)

    {

    ProcessForm(innerControl
    as HtmlForm);

    }

    }

    }

    else

    {

    //if the body tag is not runat server

    if (control is HtmlForm)

    {

    ProcessForm(control
    as HtmlForm);

    }

    if (control is HtmlControl)

    {

    ManageHTMLControl(control
    as HtmlControl);

    }

    }

    }

    My problem is I don't see the html controls that are not running at server.  Is it possible to have access to html control that are not running at server?  My conclusion is no at the moment, but I'm not sure if I'm mistaken.

    Monday, August 11, 2008 11:27 AM

Answers

  • User874596136 posted

     You can't acces HTML controls/elements from .NET code if controls are not marked with runat="server" attribute, they are not added to the controls collection.
    When page is compiled, any plain text/html is rendered as Literal controls, but they will not be accessible to you.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 11, 2008 12:55 PM