📜  ASP.Net按钮

📅  最后修改于: 2020-12-27 13:28:38             🧑  作者: Mango

ASP.NET Web窗体按钮

此控件用于执行事件。它还用于将客户端请求提交到服务器。要创建Button ,我们可以编写代码或使用Visual Studio IDE的拖放功能。

这是一个服务器端控件,asp提供了自己的标签来创建它。下面给出示例。

< asp:ButtonID="Button1" runat="server" Text="Submit" BorderStyle="Solid" ToolTip="Submit"/>

服务器将其呈现为HTML控件,并向浏览器生成以下代码。


该控件具有自己的属性,如下表所示。

Property Description
AccessKey It is used to set keyboard shortcut for the control.
TabIndex The tab order of the control.
BackColor It is used to set background color of the control.
BorderColor It is used to set border color of the control.
BorderWidth It is used to set width of border of the control.
Font It is used to set font for the control text.
ForeColor It is used to set color of the control text.
Text It is used to set text to be shown for the control.
ToolTip It displays the text when mouse is over the control.
Visible To set visibility of control on the form.
Height It is used to set height of the control.
Width It is used to set width of the control.

// WebControls.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebControls.aspx.cs" 
Inherits="WebFormsControlls.WebControls" %>



    


    

背后的代码

// 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.";
        }
    }
}

输出:

它产生以下输出。

单击时此按钮显示一条消息,如下所示。