ASP.NET Button control.
Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)
The ASP.NET Button control is used to create a push button on your webpage. The button control is rendered as the
HTML input element - type submit control.
Working example.
Click on the button example below to change the background color of the ASP.NET button control.
Example, creating the button control.
< asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Click here." BackColor="Control" />
Example code responding to the button controls click event.
The example code below is from the working example above.
< script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
if (this.Button1.BackColor == System.Drawing.Color.FromKnownColor(System.Drawing.KnownColor.Control))
{
this.Button1.BackColor = System.Drawing.Color.Red;
this.Button1.ForeColor = System.Drawing.Color.White;
return;
}
if (this.Button1.BackColor == System.Drawing.Color.Red)
{
this.Button1.BackColor = System.Drawing.Color.Purple;
return;
}
if (this.Button1.BackColor == System.Drawing.Color.Purple)
{
this.Button1.ForeColor = System.Drawing.Color.Black;
this.Button1.BackColor = System.Drawing.Color.FromKnownColor(System.Drawing.KnownColor.Control);
return;
}
}
</ script>
|