Asp.Net Button is used to submit information to the server.By default asp.net button is a Submit Button.When the user click on button then the button post back the web page to the server.To include as.net button in your project goto toolbox and double click on Button control.
<asp:Button ID="Button1" runat="server" Text="Button" />
Some Useful Properties of Asp.Net Button
Access Key Property:
Gets or Sets the access key that allows you to quickly navigate to web server control.The default value of access key is Empty which shows that this property is not set.AccessKey is used to specify the keyboard shortcut for the web server control.This allow you to access the control quickly and easily by pressing the ALT key and that key you specified on the keyboard.For example, setting the access key of a control to the string "B" shows that the user can navigate to the control by pressing ALT+B.
Remember that only a single character is allowed for the access key.If you set access key to the value that is neither null, Empty nor a single character then the exception will be thrown.
<asp:Button id="button1" accessKey="B" />
ClientID Property:
Gets the control ID for HTML markup that is generated by Asp.Net. When the web server control is rendered as an HTML element then id attribute of HTML element is set to the value of ClientID property then the clientID property is used accesscthe HTML element at client side scripting by using document.getElementById method.
ClientIDMode Property:
Gets or Sets the algorithm that is used to generate the value of ClientID property.Asp.Net provides several algorithms to define how to generate the value of clientID property.The possible values are AutoID,Static,Predictable and Inherit.
CommandName Property:
Gets or Sets the Command name associated with Button control that is passed to the Command Event.
When you have a many button controls on your web page then use the CommandName property to find out the command name associated with each button control.You can set the any string with CommandName property that identifies the command toperform then by programmatically you can get the command name of button control and perform action.
For example:
}
Enabled Property:
Gets or Sets the the value indicating whether the web server control is enabled.
ID Property:
Gets or Sets the identifier to the web server control.
OnClientClick Property:
Gets or sets the client-side script that executes when a Button control's click event is raised.
PostBackUrl Property:
Gets or sets the URL of the page to post to from the current page when the Button control is clicked.
TabIndex Property:
Gets or Sets the tab index of the web server control.
Text Property:
Gets or Sets the text to be displayed on the button control.
ToolTip Prpperty:
Gets or Sets the text to be displayed when the mouse pointer hover over the web server control.
Some Useful Methods of Button
DataBind() Method:
Binds a data source to the invoked server control and all its child controls.
Dispose() Method:
Enables a server control to perform final clean up before it is released from memory.
GetPostBackOption() Methid:
This method creates an object of PostBackOptions that shows the postback behaviour of button control.The PostBackOptions object is then passed to the ClientScriptManager.GetPostBackEventReference(PostBackOptions) method, which obtain a reference to a client-side script function that, when invoked, causes the server to post back to the page.You can override the GetPostBackOptions method in your derived class to modify the postback options for the button control.
OnClick() Method:
Callls the Click event of button control.
OnCommand() Method:
Calls the command event of button control.
OnDataBinding() Method:
Calls the DataBinding event of button control.
OnInit() Method:
Calls the Init event.
OnLOad() Method:
Calls the Load event.
OnUnload() Method:
Calls the unload event.
OpenFile() Method:
Gets a stream as a argument to read a file.
Some Useful Events of Button
Click Event:
Fires when button control is clicked.
Command Event:
Fires when button control is clicked.
DataBinding Event:
Fires when the server controls binds to a data source.
Init Event:
Occurs when server control is initialized.
<asp:Button ID="Button1" runat="server" Text="Button" />
Some Useful Properties of Asp.Net Button
Access Key Property:
Gets or Sets the access key that allows you to quickly navigate to web server control.The default value of access key is Empty which shows that this property is not set.AccessKey is used to specify the keyboard shortcut for the web server control.This allow you to access the control quickly and easily by pressing the ALT key and that key you specified on the keyboard.For example, setting the access key of a control to the string "B" shows that the user can navigate to the control by pressing ALT+B.
Remember that only a single character is allowed for the access key.If you set access key to the value that is neither null, Empty nor a single character then the exception will be thrown.
<asp:Button id="button1" accessKey="B" />
ClientID Property:
Gets the control ID for HTML markup that is generated by Asp.Net. When the web server control is rendered as an HTML element then id attribute of HTML element is set to the value of ClientID property then the clientID property is used accesscthe HTML element at client side scripting by using document.getElementById method.
ClientIDMode Property:
Gets or Sets the algorithm that is used to generate the value of ClientID property.Asp.Net provides several algorithms to define how to generate the value of clientID property.The possible values are AutoID,Static,Predictable and Inherit.
CommandName Property:
Gets or Sets the Command name associated with Button control that is passed to the Command Event.
When you have a many button controls on your web page then use the CommandName property to find out the command name associated with each button control.You can set the any string with CommandName property that identifies the command toperform then by programmatically you can get the command name of button control and perform action.
For example:
void CommandBtn_Click(Object sender, CommandEventArgs e)
{
switch(e.CommandName) { case "Asceding": // Call the method to sort the list in ascending order. Sort_List((String)e.CommandArgument); break; case "descending":
//Call the method to sort the list in descending order.
Sort_List((String)e.CommandArgument);break; default: // The command name is not recognized. Display an error message. Message.Text = "Command name not recogized."; break; }
}
Enabled Property:
Gets or Sets the the value indicating whether the web server control is enabled.
ID Property:
Gets or Sets the identifier to the web server control.
OnClientClick Property:
Gets or sets the client-side script that executes when a Button control's click event is raised.
PostBackUrl Property:
Gets or sets the URL of the page to post to from the current page when the Button control is clicked.
TabIndex Property:
Gets or Sets the tab index of the web server control.
Text Property:
Gets or Sets the text to be displayed on the button control.
ToolTip Prpperty:
Gets or Sets the text to be displayed when the mouse pointer hover over the web server control.
Some Useful Methods of Button
DataBind() Method:
Binds a data source to the invoked server control and all its child controls.
Dispose() Method:
Enables a server control to perform final clean up before it is released from memory.
GetPostBackOption() Methid:
This method creates an object of PostBackOptions that shows the postback behaviour of button control.The PostBackOptions object is then passed to the ClientScriptManager.GetPostBackEventReference(PostBackOptions) method, which obtain a reference to a client-side script function that, when invoked, causes the server to post back to the page.You can override the GetPostBackOptions method in your derived class to modify the postback options for the button control.
OnClick() Method:
Callls the Click event of button control.
OnCommand() Method:
Calls the command event of button control.
OnDataBinding() Method:
Calls the DataBinding event of button control.
OnInit() Method:
Calls the Init event.
OnLOad() Method:
Calls the Load event.
OnUnload() Method:
Calls the unload event.
OpenFile() Method:
Gets a stream as a argument to read a file.
Some Useful Events of Button
Click Event:
Fires when button control is clicked.
Command Event:
Fires when button control is clicked.
DataBinding Event:
Fires when the server controls binds to a data source.
Init Event:
Occurs when server control is initialized.
I enjoyed reading your blog! Thanks for posting such Wonderful information.
ReplyDeleteAsp.net Development | C# Development