C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
ASP.NET Web Forms ButtonThis control is used to perform events. It is also used to submit client request to the server. To create Button either we can write code or use the drag and drop facility of visual studio IDE. This is a server side control and asp provides own tag to create it. The example is given below. < asp:ButtonID="Button1" runat="server" Text="Submit" BorderStyle="Solid" ToolTip="Submit"/> Server renders it as the HTML control and produces the following code to the browser. <input name="Button1" value="Submit" id="Button1" title="Submit" style="border-style:Solid;" type="submit"> This control has its own properties that are tabled below.
Example// WebControls.aspx <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebControls.aspx.cs" Inherits="WebFormsControlls.WebControls" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:Button ID="Button1" runat="server" Text="Click here" OnClick="Button1_Click" /> </div> </form> <br /> <asp:Label ID="Label1" runat="server"></asp:Label> </body> </html> Code Behind// WebControls.aspx.cs using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace WebFormsControlls { public partial class WebControls : System.Web.UI.Page { protected void Button1_Click(object sender, EventArgs e) { Label1.Text = "You Clicked the Button."; } } } Output: It produces the following output. This button displays a message when clicked, as shown below.
Next TopicASP.NET HyperLink
|