Web and HTML server controls in asp.net 2.0

Source: Internet
Author: User

In addition to code and markup, ASP.net 2.0 pages can also contain server controls, which are programmable server-side objects that typically appear as UI elements (such as text boxes or images) on a page. The server control participates in the execution of the page and generates its own markup rendering for the client. The advantage of server controls is that it allows developers to derive complex rendering and operational behavior from simple, modular components, greatly reducing the amount of code needed to generate dynamic Web pages, and the other is that customizing their presentation and behavior is simple. The properties exposed by a server control can be set in a declarative (in markup) or programmatically (in code). The server control (and the page control itself) also exposes events that developers can handle in the course of a page execution, or in response to a client action (postback) that sends a page back to the server, the specific actions that are required to perform. Server controls also simplify the issue of reserving State information, which automatically preserves values between multiple successful "postback" operations.

A server control is declared in an. aspx file using a custom tag or an intrinsic HTML tag, and it contains the runat= "Server" property value. The intrinsic HTML markup is handled by a control in the System.Web.UI.HtmlControls namespace. Tags that are not explicitly mapped to a control are specified as System.Web.UI.HtmlControls.HtmlGenericControl types.

The following example uses four server controls:

, , , and . These server controls automatically generate HTML content at run time.

<form action="intro4_vb.aspx" method="post" runat=server>
<h3> Name: <asp:textbox id="Name" runat="server"/>
Category: <asp:dropdownlist id="Category" runat=server>
<asp:listitem >psychology</asp:listitem>
<asp:listitem >business</asp:listitem>
<asp:listitem >popular_comp</asp:listitem>
</asp:dropdownlist>
</h3>
<asp:button text="Lookup" runat="server"/>
</form>

Note that these server controls automatically retain the values entered by clients that travel to and from the server. These control states are not stored on the server (they are stored in the

In addition to supporting standard HTML input controls, ASP. NET also allows developers to use rich custom controls in their pages. For example, the following example shows how to use the control to dynamically display a scrolling advertisement on a page.

<form action="intro5_vb.aspx" method="post" runat="server">
<asp:adrotator AdvertisementFile="ads.xml" BorderColor="black" BorderWidth=1 runat="server"/>
<h3> Name: <asp:textbox id="Name" runat="server"/>
Category: <asp:dropdownlist id="Category" runat=server>
<asp:listitem >psychology</asp:listitem>
<asp:listitem >business</asp:listitem>
<asp:listitem >popular_comp</asp:listitem>
</asp:dropdownlist>
</h3>
<asp:button text="Lookup" runat="server"/>
</form>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.