Search code examples
linkbutton

How to set backcolor property of the linkbutton set to visible only if it is clicked?


I have three linkbuttons on my web page. I have provided backcolor of the linkbutton, but I want it to be visible only if that particular linkbutton is clicked. Please suggest how can I do this? My code is like this-

protected void Link_Click(object sender, EventArgs e)
    {
        LinkButton lbtn = (LinkButton)sender;
        lbtn.BackColor = System.Drawing.Color.Blue;
        string id = lbtn.ID;
        if (id == "lnkcot")
        {
           ###
        }
        else if (id == "lnktex")
        {
            ###
        }
        else if (id == "lnkgar")
        {
            ###
        }
    }

Thank You


Solution

  • I got it how to do this. . .! Just set other two link button backcolor equal to transparent. Check below.

    protected void Link_Click(object sender, EventArgs e)
                {
                    LinkButton lbtn = (LinkButton)sender;
                    lbtn.BackColor = System.Drawing.Color.Blue;
    
                    string id = lbtn.ID;
                    if (id == "lnkcot")
                    {
                        // set other two to transparent
                        lnktex.BackColor = Color.Transparent;
                        lnkgar.BackColor = Color.Transparent; 
                    }
                    else if (id == "lnktex")
                    {
                        lnkcot.BackColor = Color.Transparent;
                        lnkgar.BackColor = Color.Transparent;
                    }
                    else if (id == "lnkgar")
                    {
                        lnkcot.BackColor = Color.Transparent;
                        lnktex.BackColor = Color.Transparent;
                    }
                }