Enable Button on another Button Click using C# and VB.Net in ASP.Net

Last Reply 7 days ago By dharmendr

Posted 7 days ago

Hi

I have 2 buttons. I will disable btn1 onclick. Then i want enable btn1 only on the click of btn2.

How do i achieve this?

Please help

Posted 7 days ago

Hi suhaas121,

Refer below sample.

HTML

<asp:Button ID="btn1" Text="Button 1" runat="server" OnClick="Button1_Click" />
<asp:Button ID="btn2" Text="Button 2" runat="server" OnClick="Button2_Click" />

Code

C#

protected void Button1_Click(object sender, EventArgs e)
{
    btn1.Enabled = false;
}

protected void Button2_Click(object sender, EventArgs e)
{
    btn1.Enabled = true;
}

VB.Net

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
    btn1.Enabled = False
End Sub

Protected Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs)
    btn1.Enabled = True
End Sub