Click here to Skip to main content
15,881,089 members

Response to: How to change the color of a button on btnclick event

Revision 2
For Window Form application :

C#
private void button3_Click(object sender, EventArgs e)
        {
            button3.BackColor = System.Drawing.Color.Black;
        }



For Web Page :

On Page level declare static variable:
C#
static bool Isdefault= true;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Isdefault = false;
            }
        }


and in button click event write :
C#
protected void Button1_Click(object sender, EventArgs e)
       {
           if (!Isdefault)
           {
               Button1.BackColor = System.Drawing.Color.GreenYellow;
           }
       }
Posted 14-Jan-13 22:49pm by Ask Dj.
Tags: