📜  ASP.Net文本框

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

ASP.NET Web窗体文本框

这是一个输入控件,用于接受用户输入。要创建TextBox ,我们可以编写代码或使用Visual Studio IDE的拖放功能。

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

< asp:TextBoxID="TextBox1" runat="server" >

服务器将其呈现为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.
MaxLength It is used to set maximum number of characters that can be entered.
Readonly It is used to make control readonly.

// WebControls.aspx

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



    


    
User Name


背后的代码

// 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 SubmitButton_Click(object sender, EventArgs e)
        {
            userInput.Text = UserName.Text;
        }
    }
}

这是TextBox控件的属性窗口。

输出:

它产生以下输出。

当用户将输入提交到服务器时,它将显示用户输入。以下截屏截图并显示了用户输入。