共用方式為


How to: Set ASP.NET Web Server Control Properties

Setting a control's properties defines its appearance and behavior. This topic addresses how to set control properties declaratively.

To set server controls properties

  • In the ASP.NET Web page, set the attribute of the control declaration corresponding to the property you want.

    The exact attribute you set depends on the control and the property. For information about the properties for a specific control, search for the name of the control class (for example, "Button class (System.Web.UI.WebControls)" in the Help index.

    The following example shows how to set the MaxLength property of a TextBox control:

    Security noteSecurity Note

    A TextBox accepts user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. For more information, see Script Exploits Overview.

    <asp:textbox id="TextBox1" runat=server maxlength=20 />
    
    NoteNote

    In Web server controls, any attribute that does not map to a property of the control is passed as-is to the browser.

See Also

Tasks

How to: Set Web Server Control Properties Based on Simple Values or Enumerations
How to: Set Web Server Control Unit Properties
How to: Set Web Server Control Color Properties
How to: Set Web Server Control Properties in Collections
How to: Set HTML Attributes for Controls in ASP.NET Web Pages