Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

125
Vistas
Get HTML CheckBox state in a WebBrowser control

How can I get the state of a HTML CheckBox in a WebBrowser control?

I have the following variable in my class:

private WebBrowser quickStartGuideContentWebBrowser = new WebBrowser();

I also have the following constant in my class:

private const string doNotShowAgainCheckBoxElementId = "do-not-show-again-checkbox";

I also have the following function in my class;

private HtmlElement GetDoNotShowAgainCheckBox()
{
    HtmlDocument document = this.quickStartGuideContentWebBrowser.Document;
    if (document == null)
    {
        Debug.WriteLine("GetDoNotShowAgainCheckBox error: (document == null).");
        return null;
    }
    return document.GetElementById(doNotShowAgainCheckBoxElementId);
}

I am trying to implement a IsDoNotShowAgainCheckBoxChecked method as follows:

private bool IsDoNotShowAgainCheckBoxChecked()
{
    HtmlElement checkboxElement = GetDoNotShowAgainCheckBox();
    if (checkboxElement == null)
    {
        Debug.WriteLine("IsDoNotShowAgainCheckBoxChecked error: (checkboxElement == null).");
        return false;
    }
    // What magical incantation do I put here 
    // to retrieve the checked state of checkboxElement as a bool?
    return false;
}
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You just need to get the checked Attribute using the HtmlElement.GetAttribute() method.
It will be "True" or "False" (string), based on the state of the CheckBox.

if (quickStartGuideContentWebBrowser.ReadyState != WebBrowserReadyState.Complete) return;

var chkBoxElm = quickStartGuideContentWebBrowser.Document.
    GetElementById(doNotShowAgainCheckBoxElementId);

if (chkBoxElm != null) {
    var state = chkBoxElm.GetAttribute("checked");
    if (state = "True") {
        Console.WriteLine("The CheckBox state is 'checked'");
    }
}

The GetAttribute() method can of course be used to retrieve any other Attribute of an HtmlElement, e.g., its className.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda