.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Sandeep Singh
Melody Anderson
Eminent IT


Button Control


Introduction :

CheckBoxList Control is used for selecting one or more predefined (Available in CheckBoxList) value. That means user can able to select only one or more values at a time. For eg., it is useful for selecting the User Interest , Things user is holding etc., ASP.NET CheckBoxList itself is a class like other controls which are present under System.Web.UI.WebControls namespace.

Button Control is used to submit Page back to the Server. It's a Push Button which can be a Submit button or command Button. By Default, Button control is a Submit button until you set CommandName Property to the button Control.


So what's the difference between a Submit button and a Command button

Any submit button can be a command button if it has the commandName Property associated with it just by setting CommandName Property to any String. This will allow us to create multiple buttons in a web page and you can determine on the server side, which buton is clicked. The best example inside the GridView is we can have buttons to delete or to edit.
ASP.NET Button itself a class which is present under System.Web.UI.WebControls namespace.

Important Properties of ASP.NET Webserver  Button control. You can Set /Get these property at Design time or at Runtime.

CausesValidation -  Accept Boolean Value - Used to Validate the page when Button click event fires.

Enabled - Accept Boolean Value- Used to Get/Set button Enabled

Height - Accept IntergerValue  -  Used to Set/Get height of the textbox

OnClientClick - Accept  String value  - Used specify the client side function name (eg. Javascript function name.This property is available in .NET Framework 2.0 onwards which will execute the client side function by just setting the function name.)

Text - Accept  String -  Commenly Used property to Get/Set the the text inside the Name of the textbox which user can see.

Width - Accept IntergerValue -  Used to set the width of the Button


Events Available in Asp.Net Webserver Button Controls are:


Lets See an example:

Your .aspx code will look like this for a WebServer Control Button

<asp:Button ID="Button1" runat="server" onclientclick="MyJavaScriptFunction()"

           Text="Button" onclick="Button1_Click" />


Full Html Code with Javascript function

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title>Button Example - DotNetSpark.com</title>

    <script language="javascript" type="text/javascript">

    function MyJavaScriptFunction()







    <form id="form1" runat="server">



        <asp:Button ID="Button1" runat="server" onclientclick="MyJavaScriptFunction()"

           Text="Button" onclick="Button1_Click" />






And to assign value to the textbox programmatically in Button1_Click  Event form the .cs file

protected void Button1_Click(object sender, EventArgs e)


        Response.Write("You have clicked the button");


Other Tutorials in the same Category:
  • CheckBoxList Control      
  • Button Control      
  • Calendar Control      
  • CheckBox Control      
  • DropDownList Control or Combobox      
  • FileUpload Control      
  • Hidden Field Control      
  • ImageButton Control      
  • Link Button Control      
  • ListBox Control      
  • Literal Control      
  • RadioButton Control      
  • RadioButtonList Control      
  • TextBox Control

    Return to Main Index Page

    Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend