Button Control in ASP.Net.

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 button has a click events for write code behind code in asp.net.

Some important property of Button Control:

Simple Push button :

ID – identification of button control
Text – Display text on button control
PostBackUrl – Path of the page when redirect while click the button.
OnClientClick – write JavaScript or any client side script code function name.

Link Button :

Text – Display text on button like hyperlink.

Image Button :

ImageUrl – set image path to display image on image button control.
AlternateText – AlternateText text display when image can not display on web page.

Example of button Control in ASP.Net :

ASP.Net Button Control
ASP.Net Button Control
ASP.Net Button Control Example
ASP.Net Button Control Example
ASP.Net Button Control Example
ASP.Net Button Control Example


ASP.Net Button Control Example
ASP.Net Button Control Example

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”;

ASP.Net Button Control Example
ASP.Net Button Control Example

Leave a Reply

Your email address will not be published. Required fields are marked *