Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

147
Visualizações
Image appears after checking checkbox in HTML
protected void btnSubmit_Click(object sender, EventArgs e)
    {

        imgPurple.Visible = true;
    }

For now, I am able to make the imgPurple appear after I click btnSubmit. However, thats not what I want.

I want the imgPurple to appear when I check a checkbox, not button. How do I achieve that?

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

Do you have AutoPostBack set to true? The button you have tried will cause a postback but a checkbox change won't postback by default. This works:

<asp:CheckBox ID="CheckBox1" AutoPostBack="true" OnCheckedChanged="CheckBox1_CheckedChanged" runat="server" />

With the following:

protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {
        imgPurple.Visible = true;
    } 
about 4 years ago · Juan Pablo Isaza Relatório

0

I'm no expert in C# or .NET(If that's even the language it is), but if you compare the previous values with the current values and they are not the same, then they have changed.

So save the previous state into an object, and compare that object with the current state.

Another note, since you're not using a button as the event target, you'll probably want to use something like @Bobney was suggesting as the event handler like OnCheckedChanged as opposed to BtnSubmit_Click.

about 4 years ago · Juan Pablo Isaza Relatório

0

HTML with JavaScript:

<html>
<head>
<script>
function showPic()
{
    if (document.getElementById("myCb").checked === true)
    {
        //document.getElementById("myPic").style.display = "inline";
        document.getElementById("myPic").style.visibility = "visible";
    }
    else
    {
        //document.getElementById("myPic").style.display = "none";
        document.getElementById("myPic").style.visibility = "hidden";
    }
}
</script>
</head>
<body onload="showPic();">

<input id="myCb" type="checkbox" onclick="showPic();" /><br />
<br /> 
<img id="myPic" src="myPic.png" alt="myPic" />

</body>
</html>
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda