Exforsys

Home arrow Technical Training arrow ASP.NET Training

ASP.NET Button Controls

Page 3 of 4
Author : Exforsys Inc.     Published on: 26th Feb 2005    |   Last Updated on: 14th Mar 2011

ASP.NET Web Forms Controls

Ads

Button Controls:

Button control is also one of the most important control available for developing Asp.net forms. When ever you submit a form you need a button to tell Asp.net parser that you have completed the form that's the basic purpose of the button control. Apart from the display properties and appearance of the button control the most important event raised is button click event.

Here is what the button click event looks like:

Sample Code
  1. private void Button2_Click(object sender, System.EventArgs e) {
  2.  
  3.         }
Copyright exforsys.com


Here the name of the button is Button2, which is the id of the button. The button event takes two parameters which are object sender and System.EventArgs.

the object sender specifies that which button on the form has been clicked. And the next parameter System.EventArgs tells the asp.net that what is being send to the button method.

Below is the list of all the events supported by button control.

Public Events

 

public eventClick Occurs when the Button control is clicked.
public eventCommand Occurs when the Button control is clicked.
public eventDataBinding (inherited from Control) Occurs when the server control binds to a data source.
public eventDisposed (inherited from Control) Occurs when a server control is released from memory, which is the last stage of the server control lifecycle when an ASP.NET page is requested.
public eventInit (inherited from Control) Occurs when the server control is initialized, which is the first step in the its lifecycle.
public eventLoad (inherited from Control) Occurs when the server control is loaded into thePage object.
public eventPreRender (inherited from Control) Occurs when the server control is about to render to its containing Page object.
public eventUnload (inherited from Control) Occurs when the server control is unloaded from memory.

 

Lets make a small application that will change the text in the TextBox when the button is clicked.

Sample Code
  1. private void Button2_Click(object sender, System.EventArgs e) {
  2.         TextBox1.Text = "This is my new Text";
  3. }
Copyright exforsys.com


As you see its very simple to raise and capture, capture and take action on the event.

Ads


 
This tutorial is part of a ASP.NET Training tutorial series. Read it from the beginning and learn yourself.

ASP.NET Training

 

Comments