📜  ASP.Net HTML Server控件

📅  最后修改于: 2020-12-28 00:36:20             🧑  作者: Mango

ASP.NET HTML服务器控件

HTML服务器控件是HTML元素,包含可在服务器端访问的属性。默认情况下,ASP.NET网页上的HTML元素对服务器不可用。这些组件被视为简单文本,并传递到浏览器。我们可以通过向组件添加runat =“ server”id属性来将HTML元素转换为服务器控件。

现在,我们可以在后面的代码中轻松访问它。


可以通过Request对象访问所有HTML Server控件。

HTML组件

下表包含常用的HTML组件。

Controls Name Description
Button It is used to create HTML button.
Reset Button It is used to reset all HTML form elements.
Submit Button It is used to submit form data to the server.
Text Field It is used to create text input.
Text Area It is used to create a text area in the html form.
File It is used to create a input type = “file” component which is used to upload file to the server.
Password It is a password field which is used to get password from the user.
CheckBox It creates a check box that user can select or clear.
Radio Button A radio field which is used to get user choice.
Table It allows us to present information in a tabular format.
Image It displays an image on an HTML form
ListBox It displays a list of items to the user. You can set the size from two or more to specify how many items you wish to show.
Dropdown It displays a list of items to the user in a dropdown list.
Horizontal Rule It displays a horizontal line across the HTML page.

在这里,我们以表单的形式实现HTML服务器控件。

// htmlcontrolsexample.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="htmlcontrolsexample.aspx.cs" 
Inherits="asp.netexample.htmlcontrolsexample" %>






该应用程序包含文件背后的代码。

// htmlcontrolsexample.aspx.cs

using System;
namespace asp.netexample
{
public partial class htmlcontrolsexample : System.Web.UI.Page
    {
protected void Page_Load(object sender, EventArgs e)
        {
        }
protected void Button1_Click(object sender, EventArgs e)
        {
string a = Request.Form["Text1"];
            Response.Write(a);
        }
    }
}

输出:

当我们在输入文本后单击按钮时,它会回复给客户。