Using the ImageButton control in C#

The ImageButton control is used to display a clickable image on a webpage that can be used to perform a postback to the web server when the image is clicked.This control generates an input type=”image” element when rendering to HTML.

public partial class ImageButton_Control: System.Web.UI.Page 
{  
  protected void Page_Load(object sender, EventArgs e)  
  {  
    ImageButton1.ImageUrl= "~/images/redblue.jpg"; 
    ImageButton1.AlternateText =  
      "This is a button.The left side is red.The right is blue."; 
  }  
  protected void ImageButton1_Click(object sender, ImageClickEventArgs e)  
  {  
    ImageButton1.AlternateText = string.Format("Button Clicked at {0}, {1}", e.X, e.Y);  
  }  
}

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.