Reputation:
How can I change the color of a button when it is clicked in asp.net? In my code color is changing when mouse over it. But I need to change when button clicking.
Upvotes: 0
Views: 4591
Reputation: 8736
try this
<asp:Button Text="Save" ID="btnSave" OnClick="btnSave_Click" runat="server" />
code behind
protected void btnSave_Click(object sender, EventArgs e)
{
btnSave.BackColor = System.Drawing.Color.Red;
}
Upvotes: 1
Reputation: 778
Try this,
<input id="btnTest" type="button" value="Test"/>
$(document).ready(function() {
$("#btnTest").click(function() {
$("#btnTest").css("background-color","red");
});
});
Upvotes: 0
Reputation: 3469
OnClientClick="this.src='Images/image.jpg';return false;"
add that to your button line's source
Upvotes: 0
Reputation: 460298
Perhaps i'm missing something obvious, but isn't it as simple as:
Change onmouseover
to onclick
.
If you want to do it on serverside, handle it's Click
event and:
Button1.ForeColor = Color.Red;
Button1.BackColor = Color.Black;
Upvotes: 1