Button Control in ASP.Net web server control, button control is used to display a simple push button on a web page. We can display a simple push button on the web page by adding Button Control to the asp.net web page.
Asp.net has three types of Button: –
Types of Button Control in ASP.Net
- Simple push button – Simple Push Button displays text on Button Control.
- Link button – Link button displays text that looks like a link or hyperlink.
LinkButton </ asp: LinkButton> - Image button – Image Button displays an image on a button control.
The main two events in these three Button are Click and Command event. By default there are click events in asp.net Button. Here we will understand all three button controls with an asp.net instance.
ASP. Button Control example in Net
Step 1 – Open Visual Studio -> Create a new blank web application.
Step 2 – Create a new web page for the display button on it.
Step 3 – Drag and drop the button control on the web page from the toolbox.
Step 4 – Set the text property of the button control.
Step 5 – Set the PostBackUrl property to redirect the second page.
Step 6 – To write the code on the button control, go to the click event of button control.
All three buttons have a click event to write server side code (C #, VB) in ASP.NET. All server side control has its own properties and events. Button control properties are shown in the list below.
Properties | Description | |
ID | identification name of textbox control | |
Text | It is used to display text in a control. | |
Backcolor | This is used to set the background color of the textbox control. | |
Forcolor | This is used to set the control’s text color. | |
ToolTip | When the mouse is over the text, it displays the text on the control. | |
TabIndex | This is used to manage the tab order of the control. | |
CssClass | This is used to apply style to the control. | |
Enable | true / false – This is used to enable or disable control. | |
Enable Theming | true / false – This is used to enable or disable the theme’s effect on control. | |
CausesValidation | true / false – This is used to enable or disable the effect of validation on control | |
Visible | true / false – This is used to hide or hide the control on a web page. |
Important properties of Button control
CommandArgument | A string value is passed behind the code when the button command event is fired. |
Commandname | A string value is passed behind the code when the button command event is fired. |
OnClientClick | JavaScript function name or any client-side script code function name. |
PostBackUrl | The URL of the page is redirected by clicking on the button. |
For Image Button | |
ImageUrl | Set the image path to display the image on the Image Button control. |
AlternateText | Alternate text will be displayed when the image cannot be displayed on the web page. |
Button Control Events
Events | Description |
Click | Button Click event occurs when button control is clicked. First click eventHandler is executed, after that the command handler is executed. |
Command | Button Command event occurs when button control is clicked. |
Button Click and Command events are both the same. The only difference is that in Command we can pass the command name and the command argument. For example, we have two control buttons, both calling the same command event, we can identify which button is clicked by reaching their command name, because we have different command names for both buttons. Assign.
The design of the asp.net web form with Button Control and Label Control looks like the screen below. To display the message on the label control in asp.net, type the code as follows in the button click event: –
protected void btnlogin_Click(object sender, EventArgs e)
{
Label1.Text = "welcome";
}