Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Easy question: how to change button color when clicking on it?

Status
Not open for further replies.

eramgarden

Programmer
Aug 27, 2003
279
US
Still upgrading ASP to ASP.Net...

The pages I inherited have an image with text over it that is used as a button...Done with HTML... (but it's actually not a button)...so when i click on it, it takes me to another page...

I want to have a button that when I click on it, it changes the color of it ..this way if i have a left side menu, i can tell which link/button i have clicked on...

I can do this with JavaScript and creating button images ....but can I do it in ASP.Net...

Have buttons, i click on it, it changes the color?
 
Are you using an ImageButton control? If you are posting back to redirect, then you can change the back color in code behind:
Code:
private void imgButton_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
 if(imgButton.BackColor == Color.Red)
 {
  imgButton.BackColor = Color.Green;
 }
 else
 {
  imgButton.BackColor = Color.Red;
 }
 //Server.Transfer("anotherpage.aspx");
}

<asp:ImageButton id=imgButton BackColor=red runat=&quot;server&quot; ImageUrl=&quot;image.jpg&quot; />
 
Thanks LV for your response, I'm receiving my .Net book today :)

I'm not using ImageButton, didnt even know about such control. This will give me head start on what to research and go about.

Will post more questions when I implement what you gave me.

Thanks again.
 
Let me ask you this, would you do it that way...is that way a good method or should create buttons via photoshop and have 2 sets of buttons for each menu link and use Javascript to change them??
 
If you've desided to use .Net, then it won't be wise to throw away whatever's already built in, though it could be an additional hit on the server. Although sometimes it's useful to use javascript as well, and you can do it in .Net.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top