In this article, I am going to describe what are the main differences between asp:LinkButton, asp:ImageButton, asp:Button and asp:HyperLink control and how/where to use them effectively.
Introduction
In our day to day programming, we almost daily use asp:LinkButton, asp:ImageButton, asp:Button and asp:HyperLink controls. I am trying to describe what are the main differences and similarities between them and where/how to use them effectively.asp:LinkButton Control
LinkButton control is a control just like a Button control along with the flexibility to make it look like a Hyperlink. It implements an anchor tag that uses only ASP.NET postback mechanism to post the data on the server. Despite being a hyperlink, you can't specify the target URL. 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 TextBox tag. You can set its Text property either by setting Text properties in the .aspx page or from server side page. (other properties can also be set from both sides)Following are some important properties that are very useful.
CausesValidation | Value can be set as true/false. This indicates whether validation will be performed when this button will be clicked. |
PostBackUrl | Indicates the URL on which the Form will be posted back if 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. |
Where /When to use asp:LinkButton Conntrol
Usually, this control is used to give a uniform look and feel through out the page/site if you are using hyperlink to navigate through the site. Also if you have less space and want to show a control that can actually fire server side event, placing Button control will not work as this take more space as well as its look and feel is completely different than LinkButton control.
For more details and demo: http://www.dotnetfunda.com/tutorials/controls/linkbutton.aspx
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 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 TextBox 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. |
Where / When to use asp:ImageButton Conrol?
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.
For more details and demo: http://www.dotnetfunda.com/tutorials/controls/imagebutton.aspx
asp:Button Control
Button control is used to post the form or fire an event either client side or server side. Button 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, it is generally implemented through HTML tag. However, if UserSubmitBehavior property is set to false then control will render out as Button.Its properties like BackColor, ForeColor, BorderColor, BorderStyle, BorderWidth, Height etc. are implemented through style properites of input tag. You can set its Text property either by setting Text property in the .aspx page or from server side page. (other properties can also be set from both pages)
A button can be set as default button (Default button is a button that fires automatically when an user presses Enter key while filling a form.) by specifying DefaultButton property of the
No comments:
Post a Comment