Where & When to use asp:ImageButton Control?

ImageButton control is used to post the form or fire an event either client side or server side. Its like a asp:Button control, the only difference is, you have the ability to place your own image as a button. ImageButton control is generally used to post the form or fire an event either client side or server side. When it is rendered on the page, generally it is implemented through <input type=image > HTML tag.
There is no UserSubmitBehavior property like Button control with this control.
Its properties like BackColor, ForeColor, BorderColor, BorderStyle, BorderWidth, Height etc. are implemented through style properites of <input> tag. You can set its Image location either by setting ImageURL properties in the .aspx page or from server side page. (other properties can also be set from both pages)
Following are some important properties that are very useful.

ImageUrl Gets or Sets the location of the image to display as button control.
CausesValidation Value can be set as true/false. This indicates whether validation should be performed when this button is clicked.
PostBackUrl Indicates the URL on which the Form will be posted back when this button will be clicked.
ValidationGroup Gets or Sets the name of the validation group that the button belongs to. This is used to validate only a set of Form controls with this Button.
OnClick Attach a server side method that will fire when this button will be clicked.
OnClientClick Attach a client side (javascript) method that will fire when this button will be clicked.

As in the case of LinkButton, ImageButton control will also not work if JavaScript is disabled in the browser as ASP.NET write its own function to post data to the server when this button is clicked.
Usually, this control is used to attract user attention and maintain uniformity thorugh out the site. You can create same type (look and feel) of image for every action user need to perform in your website/application and use it.

Tagged . Bookmark the permalink.

Leave a Reply