Click here to Skip to main content
15,896,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to make the image in imagebutton changes when it is clicked. I use the OnClick method.

This is the code I've tried but doesn't work.

C#
protected void SignIn_Click(object sender, ImageClickEventArgs e)
        {
            if (ImageField.ThisExpression == this.ResolveClientUrl("~/Images/click.png"))
            {
                ImageButton.DisabledCssClass = this.ResolveClientUrl("~/Images/click.png");
            }
        }
Posted

1 solution

My solution is to use javascript and place it in between the of the aspx page.
XML
<script type="text/javascript">
       function abc(signOut) {
           var img = document.getElementById(signOut.id);
           img.src = "/Images/click.png";
           return false;
       }
   </script>



And this is my imagebutton in gridview...

XML
<asp:TemplateField HeaderText="Sign Out">
                    <ItemTemplate>
                        <asp:ImageButton OnClientClick="return abc(this);" ID="signOut" CommandName="Insert" AlternateText="Available" ImageUrl="~/Images/unclick.png" runat="server" />
                    </ItemTemplate>
                </asp:TemplateField>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900