So this is working well for me so far but I do not want to make a new method for every image on the page. How do I get the control “Card” in the codebehind method when it is called so I can use the same method on every image button. Is there a better way to do this? All I want is to rotate an image 90 deg when clicked and, when clicked again rotate the image back. The problem is that I want to use only one method that will rotate any image.
protected void Card_Click(object sender, ImageClickEventArgs e)
{
if (Card.CssClass == "rotate90Large")
{
Card.CssClass = "";
}
else
{
Card.CssClass = "rotate90Large";
}
}
.aspx
<style type="text/css">
.rotate90Large{-ms-transform: rotate(90deg); margin-left:45px; }
</style>
<asp:ImageButton ID="Card" ImageUrl="Graphics/image.jpg" runat="server" onclick="Card_Click" />
Casting the sender should be sufficient, and you can subscribe all image buttons to the same click event, in your case
Card_Click