ASP.Net Button Control
In this asp.net tutorials we will learn how to use Button control in ASP.Net.
The Button is an asp.net web server control.
The Button control is used to display a simple push button on web page.
we can display a simple push button on a web page by adding button control on asp.net web page.
Refer this link for ImageButton Control and LinkButton Control in ASP.Net.
There are three type of button in asp.net.
1. Simple Push Button
– Simple Push Button displays text on a button control.
2. Link Button
– Link button displays text that looks like a link or hyperlink.
3. Image Button
– Image Button displays an image on a button control.
All these three button has main two events Click and Command events. By default in asp.net button has click events.
Here we will understand all three button control with an asp.net example.
Button Control Example in ASP.Net.
Step 1 – Open the Visual Studio –> Create a new empty Web application.
Step 2 – Create a New web page for display button on it.
Step 3 – Drag and drop Button control on web page from Toolbox.
Step 4 – Set Text property of Button Control
Step 5 – For Redirect other page set PostBackUrl Property to destination web page name.
Step 6 – For write code on button control go to Click events of button control.
ASP.Net Button Control Example:
The Simple Button code is like:
<asp:Button ID=”Button1″ runat=”server” Text=”Button” />
The Link Button code is like:
<asp:LinkButton ID=”LinkButton1″ runat=”server”>LinkButton</asp:LinkButton>
The Image Button code is like:
<asp:ImageButton ID=”ImageButton1″ runat=”server” />
All three buttons has a click events for write server side code (c#, vb) in asp.net.
All server side control has its own properties and events. below list shows Button control properites.
Properties | Description |
---|---|
ID | Identification name of textbox control. |
Text | It is used to display text in a control. |
BackColor | It is used to set background color of textbox control. |
ForColor | It is used to set text color of the control. |
ToolTip | It displays a text on control when mouse over on it. |
TabIndex | It is used manage tab order of control. |
CssClass | It is used to apply style on control. |
Enable | true/false – used to enable or disable control. |
Enable Theming | true/false – It is used to enable or disable effect of theme on control. |
CausesValidation | true/false – It is used to enable or disable validation effect on control |
Visible | true/false – It is used to hide or visible control on web page. |
Important Properties of Button control | |
CommandArgument | A string value passed to code behind when button Command event is fired. |
CommandName | A string value passed to code behind when button Command event is fired. |
OnClientClick | The JavaScript function name or any client side script code function name. |
PostBackUrl | The URL Path of the page to redirect, when button is clicked. |
For Image Button | |
ImageUrl | Set image path to display image on image button control. |
AlternateText | Alternate text will be displayed when image cannot be displayed on web page. |
Example of button Control in ASP.Net :



Button Control Events
Events | Description |
---|---|
Click | Button Click event occurs when the button control is clicked. The Click eventHandler is performed first, then commandHandler. |
Command | Button Command event occurs when the button control is clicked. |

Design asp.net web form with Button Control and Label Control look like below screen. write below code in button click event for display message on label control in asp.net
protected void btnlogin_Click(object sender, EventArgs e)
{
Label1.Text = "welcome";
}
