for RuBoard |
In this section we'll take a look, one by one, at the HTML controls provided by ASP.NET and show you examples of some of the more interesting ones.
Member of System.Web.UI.HtmlControls.
Assembly: System.Web.Dll.
The HtmlAnchor control encapsulates the <a> tag with a server-side control model. You shouldn't use this for every link, but it makes it easy to dynamically generate links as needed.
Properties | ||
---|---|---|
Attributes | ClientID | Controls |
Disabled | EnableViewState | Href |
ID | InnerHtml | InnerText |
Name | NamingContainer | Page |
Parent | Site | Style |
TagName | Target | TemplateSourceDirectory |
Title | UniqueID | Visible |
Methods | ||
DataBind | Dispose | Equals |
FindControl | GetHashCode | GetType |
HasControls | RenderControl | ResolveUrl |
ToString | ||
Events | ||
DataBinding | Disposed | Init |
Load | PreRender | ServerClick |
Unload |
Listings 2.10 and 2.11 show a page that alters a link based on whether the page containing the link is accessed using HTTPS . This is a frequent requirement when building secure e-commerce Web sites.
<%@ Page language="c#" Codebehind="Anchor.aspx.cs" AutoEventWireup="false" Inherits="HtmlControls.Anchor" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > <HTML> <HEAD> <title>Dynamically Generated Anchor</title> <meta name="GENERATOR" Content="Microsoft Visual Studio 7.0"> <meta name="CODE_LANGUAGE" Content="C#"> <meta name="vs_defaultClientScript" content="JavaScript"> <meta name="vs_targetSchema" content="http://schemas.microsoft.com/ intellisense/ie5"> </HEAD> <body> <form id="Anchor" method="post" runat="server"> <a id="AnchorTag" runat="server">Test Anchor</a> </form> </body> </HTML>
using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; namespace HtmlControls { public class Anchor : System.Web.UI.Page { protected System.Web.UI.HtmlControls.HtmlAnchor AnchorTag; private void Page_Load(object sender, System.EventArgs e) { if(Page.Request.IsSecureConnection) { AnchorTag.HRef = "https://www.deeptraining.com"; AnchorTag.InnerText = "Secure Link"; } else { AnchorTag.HRef = "http://www.deeptraining.com"; AnchorTag.InnerText = "Unsecure Link"; } } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.Load += new System.EventHandler(this.Page_Load); } #endregion } }
The ServerClick event enables you to optionally process the anchor on the server side instead of the client side. This adds an extra round trip to the action but allows you to treat text just like buttons that invoke server-side actions. The InnerText or InnerHtml properties enable you to alter the content between the <a> and </a> tags, as shown in Listing 2.11. The Title property corresponds to the alt text or ToolTip that pops up for an anchor. The code in Listings 2.10 and 2.11 was generated using VS.NET as opposed to Listings 2.8 and 2.9, which used Notepad.
Member of System.Web.UI.HtmlControls.
Assembly: System.Web.dll.
The HtmlButton class provides a server-side encapsulation of the HTML 4.0 <button> tag. It works only in Internet Explorer 4.0 and later. If you want to use a button that works in a wider variety of browsers, take a look at HtmlInputButton later on in this section.
Properties | ||
---|---|---|
Attributes | CausesValidation | ClientID |
Controls | Disabled | EnableViewState |
ID | InnerHtml | InnerText |
NamingContainer | Page | Parent |
Site | Style | TagName |
TemplateSourceDirectory | UniqueID | Visible |
Methods | ||
DataBind | Dispose | Equals |
FindControl | GetHashCode | GetType |
HasControls | RenderControl | ResolveUrl |
ToString | ||
Events | ||
DataBinding | Disposed | Init |
Load | PreRender | ServerClick |
Unload |
This control is primarily used to kick off some server-side processing. This is done through the ServerClick event. Listings 2.12 and 2.13 show a page with an HtmlButton control that fires off some script in the page to write some text to the page.
<%@ Page language="c#" Codebehind="Button.aspx.cs" AutoEventWireup="false" Inherits="HtmlControls.Button" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > <HTML> <HEAD> <title>HtmlButton Class</title> <meta name="GENERATOR" Content="Microsoft Visual Studio 7.0"> <meta name="CODE_LANGUAGE" Content="C#"> <meta name="vs_defaultClientScript" content="JavaScript"> <meta name="vs_targetSchema" content="http://schemas.microsoft.com/ intellisense/ie5"> </HEAD> <body> <form id="Button" method="post" runat="server"> <button id="btnClick" title="" type="button" runat="server">Click Me</button> </form> </body> </HTML>
using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; namespace HtmlControls { /// <summary> /// Summary description for Button. /// </summary> public class Button : System.Web.UI.Page { protected System.Web.UI.HtmlControls.HtmlButton btnClick; private void Page_Load(object sender, System.EventArgs e) { btnClick.InnerText = "Click Me!"; } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.btnClick.ServerClick += new System.EventHandler(this.btnClick_ServerClick); this.Load += new System.EventHandler(this.Page_Load); } #endregion private void btnClick_ServerClick(object sender, System.EventArgs e) { Response.Write("You clicked me!"); } } }
Member of System.Web.UI.HtmlControls.
Assembly: System.Web.dll.
The HtmlForm class allows you to change the properties of a form on the server side. These properties include the target you are posting to as well as the method used to send the data to the server.
Properties | ||
---|---|---|
Attributes | ClientID | Controls |
Disabled | EnableViewState | EncType |
ID | InnerHtml | InnerText |
Method | Name | NamingContainer |
Page | Parent | Site |
Style | TagName | Target |
TemplateSourceDirectory | UniqueID | Visible |
Methods | ||
DataBind | Dispose | Equals |
FindControl | GetHashCode | GetType |
HasControls | RenderControl | ResolveUrl |
ToString | ||
Events | ||
DataBinding | Disposed | Init |
Load | PreRender | Unload |
The EncType property controls the encoding of the form. Valid encoding types include "multipart/form-data", "text/plain", and "image/jpeg". Listing 2.14 and 2.15 alter the Method property to determine how the form data is posted to the server.
NOTE
Only one <form runat=server> tag is allowed per page. You might initially think this is a limitation; however, the routing of events by ASP.NET alleviates this problem immensely.
<%@ Page language="c#" Codebehind="Form.aspx.cs" AutoEventWireup="false" Inherits="HtmlControls.Form1" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > <HTML> <HEAD> <title>Dynamically Altering Form Method</title> <meta name="GENERATOR" Content="Microsoft Visual Studio 7.0"> <meta name="CODE_LANGUAGE" Content="C#"> <meta name="vs_defaultClientScript" content="JavaScript"> <meta name="vs_targetSchema" content="http://schemas.microsoft.com/ intellisense/ie5"> </HEAD> <body> <form id="Form" method="post" runat="server"> <asp:RadioButtonList id="RadioButtonList1" runat="server" AutoPostBack="True"> <asp:ListItem Selected="True" Value="Post">Post</asp:ListItem> <asp:ListItem Value="Get">Get</asp:ListItem> </asp:RadioButtonList> </form> </body> </HTML>
using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; namespace HtmlControls { /// <summary> /// Summary description for Form. /// </summary> public class Form1 : System.Web.UI.Page { protected System.Web.UI.WebControls.RadioButtonList RadioButtonList1; protected System.Web.UI.HtmlControls.HtmlForm Form; private void Page_Load(object sender, System.EventArgs e) { Response.Write("Form Method used to Send: " + Form.Method); } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.RadioButtonList1.SelectedIndexChanged += new System.EventHandler(this.RadioButtonList1_SelectedIndexChanged); this.ID = "Form1"; this.Load += new System.EventHandler(this.Page_Load); } #endregion private void RadioButtonList1_SelectedIndexChanged(object sender, System.EventArgs e) { Form.Method = RadioButtonList1.SelectedItem.Value; } } }
NOTE
In the code example in Listing 2.15, you will have to press the radio button twice to see the results. This is because the procedure that outputs the form method runs prior to the RadioButtonList1_SelectedIndexChanged event that actually alters the way the form works.
Member of System.Web.UI.HtmlControls.
Assembly: System.Web.dll.
The HtmlImage class encapsulates the HTML <img> tag. This can be useful for dynamically pointing to multiple images on your site. Note that this does not enable you to send the actual image data. You can alter only where the browser retrieves the image data from.
Properties | ||
---|---|---|
Align | Alt | Attributes |
Border | ClientID | Controls |
Disabled | EnableViewState | Height |
ID | NamingContainer | Page |
Parent | Site | Src |
Style | TagName | TemplateSourceDirectory |
UniqueID | Visible | Width |
Methods | ||
DataBind | Dispose | Equals |
FindControl | GetHashCode | GetType |
HasControls | RenderControl | ResolveUrl |
ToString | ||
Events | ||
DataBinding | Disposed | Init |
Load | PreRender | Unload |
Listings 2.16 and 2.17 use the image-specific properties of this server control to allow you to alter how an image is displayed on the page.
<%@ Page language="c#" Codebehind="Image.aspx.cs" AutoEventWireup="false" Inherits="HtmlControls.Image" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > <HTML> <HEAD> <title>Image Properties</title> <meta name="GENERATOR" Content="Microsoft Visual Studio 7.0"> <meta name="CODE_LANGUAGE" Content="C#"> <meta name="vs_defaultClientScript" content="JavaScript"> <meta name="vs_targetSchema" content="http://schemas.microsoft.com/ intellisense/ie5"> </HEAD> <body> <form id="Image" method="post" runat="server"> <table> <tr> <td> <img src="deeplogo2.jpg" runat="server" id="IMG1"> </td> </tr> <tr> <td> Alt: <input type="text" id="txtAlt" runat="server" value="Deep Logo" NAME="txtAlt"> <br> <input type="checkbox" id="chkBorder" runat="server" NAME="chkBorder">Border <input type="checkbox" id="chkVisible" runat="server" Checked NAME="chkVisible">Visible <br> Alignment: <select id="ddAlignment" runat="server" NAME="ddAlignment"> <option Value="left" selected> Left</option> <option Value="center"> Center</option> <option Value="right"> Right</option> <option Value="top"> Top</option> <option Value="middle"> Middle</option> <option Value="bottom"> Bottom</option> </select> <br> Size: <input type="text" id="txtWidth" runat="server" Width="51px" Height="24px" NAME="txtWidth"> x <input type="text" id="txtHeight" runat="server" Width="51px" Height="24px" NAME="txtHeight"> <br> Src: <input type="text" id="txtSrc" runat="server" value="deeplogo2.jpg" NAME="txtSrc"> <P></P> <P> </P> <P> <input type="submit" id="btnApply" runat="server" Value="Apply Settings" NAME="btnApply"> </P> </td> </tr> </table> </form> </body> </HTML>
using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; namespace HtmlControls { /// <summary> /// Summary description for Image. /// </summary> public class Image : System.Web.UI.Page { protected System.Web.UI.HtmlControls.HtmlImage IMG1; protected System.Web.UI.HtmlControls.HtmlInputText txtAlt; protected System.Web.UI.HtmlControls.HtmlInputCheckBox chkBorder; protected System.Web.UI.HtmlControls.HtmlInputCheckBox chkVisible; protected System.Web.UI.HtmlControls.HtmlSelect ddAlignment; protected System.Web.UI.HtmlControls.HtmlInputText txtWidth; protected System.Web.UI.HtmlControls.HtmlInputText txtHeight; protected System.Web.UI.HtmlControls.HtmlInputText txtSrc; protected System.Web.UI.HtmlControls.HtmlInputButton btnApply; private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.btnApply.ServerClick += new System.EventHandler(this.btnApply_ServerClick); this.Load += new System.EventHandler(this.Page_Load); } #endregion private void btnApply_ServerClick(object sender, System.EventArgs e) { // Set the alt text IMG1.Alt = txtAlt.Value; // If the border is checked set a border width if(chkBorder.Checked) IMG1.Border = 5; else IMG1.Border = 0; // Set the image alignment IMG1.Align = ddAlignment.Items[ddAlignment.SelectedIndex].Value; // If a width is entered then set it if(txtWidth.Value != "") IMG1.Width = int.Parse(txtWidth.Value); // If a height is entered then set it if(txtHeight.Value != "") IMG1.Height = int.Parse(txtHeight.Value); // Set the image to show IMG1.Src = txtSrc.Value; // Set whether it is visible IMG1.Visible = chkVisible.Checked; } } }
Member of System.Web.UI.HtmlControls.
Assembly: System.Web.dll.
The HtmlInputButton class wraps up several HTML tags, including <input type=button> , <input type=reset> , and <input type=submit> . This class is supported in all browsers (unlike the HtmlButton class).
Properties | ||
---|---|---|
Attributes | CausesValidation | ClientID |
Controls | Disabled | EnableViewState |
ID | Name | NamingContainer |
Page | Parent | Site |
Style | TagName | TemplateSourceDirectory |
Type | UniqueID | Value |
Visible | ||
Methods | ||
DataBind | Dispose | Equals |
FindControl | GetHashCode | GetType |
HasControls | RenderControl | ResolveUrl |
ToString | ||
Events | ||
DataBinding | Disposed | Init |
Load | PreRender | ServerClick |
Unload |
Listings 2.18 and 2.19 show the difference in behavior between the type=submit and type=reset buttons.
<%@ Page language="c#" Codebehind="InputButton.aspx.cs" AutoEventWireup="false" Inherits="HtmlControls.InputButton" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > <HTML> <HEAD> <title>HtmlInputButton Example</title> <meta name="GENERATOR" Content="Microsoft Visual Studio 7.0"> <meta name="CODE_LANGUAGE" Content="C#"> <meta name="vs_defaultClientScript" content="JavaScript"> <meta name="vs_targetSchema" content="http://schemas.microsoft.com/ intellisense/ie5"> </HEAD> <body> <form id="InputButton" method="post" runat="server"> <asp:TextBox id="TextBox1" runat="server"></asp:TextBox> <input type="submit" id="btnSubmit" runat="server" value="Submit" NAME="btnSubmit"> <input type="reset" id="btnReset" runat="server" value="Reset" NAME="btnReset"> </form> </body> </HTML>
using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; namespace HtmlControls { /// <summary> /// Summary description for InputButton. /// </summary> public class InputButton : System.Web.UI.Page { protected System.Web.UI.WebControls.TextBox TextBox1; protected System.Web.UI.HtmlControls.HtmlInputButton btnSubmit; protected System.Web.UI.HtmlControls.HtmlInputButton btnReset; private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.btnSubmit.ServerClick += new System.EventHandler(this.btnSubmit_ServerClick); this.btnReset.ServerClick += new System.EventHandler(this.btnReset_ServerClick); this.Load += new System.EventHandler(this.Page_Load); } #endregion private void btnSubmit_ServerClick(object sender, System.EventArgs e) { Response.Write("You clicked submit."); } private void btnReset_ServerClick(object sender, System.EventArgs e) { Response.Write("You clicked reset."); } } }
Member of System.Web.UI.HtmlControls.
Assembly: System.Web.dll.
HtmlInputCheckBox encapsulates the <input type=checkbox> tag. The Checked property indicates whether the item was checked. Listing 2.17 uses the HtmlInputCheckbox to indicate the visibility of the image. The ServerChange event can be used to catch the change in value of the control on the server.
Properties | ||
---|---|---|
Attributes | Checked | ClientID |
Controls | Disabled | EnableViewState |
ID | Name | NamingContainer |
Page | Parent | Site |
Style | TagName | TemplateSourceDirectory |
Type | UniqueID | Value |
Visible | ||
Methods | ||
DataBind | Dispose | Equals |
FindControl | GetHashCode | GetType |
HasControls | RenderControl | ResolveUrl |
ToString | ||
Events | ||
DataBinding | Disposed | Init |
Load | PreRender | ServerChange |
Unload |
Member of System.Web.UI.HtmlControls.
Assembly: System.Web.dll.
Provides a way for you to upload files to the server. This control encapsulates the <input type=file> tag on the client and also provides a way to extract the file information from the posted data. For this control to work, the EncType of the form must be set to multipart/form-data.
Properties | ||
---|---|---|
Accept | Attributes | ClientID |
Controls | Disabled | EnableViewState |
ID | MaxLength | Name |
NamingContainer | Page | Parent |
PostedFile | Site | Size |
Style | TagName | TemplateSourceDirectory |
Type | UniqueID | Value |
Visible | ||
Methods | ||
DataBind | Dispose | Equals |
FindControl | GetHashCode | GetType |
HasControls | RenderControl | ResolveUrl |
ToString | ||
Events | ||
DataBinding | Disposed | Init |
Load | PreRender | Unload |
Listings 2.20 and 2.21 show a page that collects the name of a file from the user and then uploads it to the server. On the server side we grab the content of the posted file and place it into a text area. The Accept property is used to indicate that only files with a MIME type of text are allowed to be uploaded.
<%@ Page language="c#" Codebehind="InputFile.aspx.cs" AutoEventWireup="false" Inherits="HtmlControls.InputFile" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > <HTML> <HEAD> <title>Input File Example</title> <meta name="GENERATOR" Content="Microsoft Visual Studio 7.0"> <meta name="CODE_LANGUAGE" Content="C#"> <meta name="vs_defaultClientScript" content="JavaScript"> <meta name="vs_targetSchema" content="http://schemas.microsoft.com/ intellisense/ie5"> </HEAD> <body> <form id="InputFile" method="post" runat="server" enctype="multipart/ form-data"> <input type="file" id="FilePost" runat="server" NAME="FilePost"><input type="submit" id="btnSubmit" runat="server" value="Send File" NAME="btnSubmit"> <br> <textarea id="txtOutput" runat="server" style="WIDTH: 733px; HEIGHT: 630px" rows="39" cols="89" NAME="txtOutput"></textarea> </form> </body> </HTML>
using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; namespace HtmlControls { /// <summary> /// Summary description for InputFile. /// </summary> public class InputFile : System.Web.UI.Page { protected System.Web.UI.HtmlControls.HtmlInputFile FilePost; protected System.Web.UI.HtmlControls.HtmlInputButton btnSubmit; protected System.Web.UI.HtmlControls.HtmlTextArea txtOutput; private void Page_Load(object sender, System.EventArgs e) { FilePost.Accept = "text/*"; } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.btnSubmit.ServerClick += new System.EventHandler(this.btnSubmit_ServerClick); this.Load += new System.EventHandler(this.Page_Load); } #endregion private void btnSubmit_ServerClick(object sender, System.EventArgs e) { System.IO.StreamReader tr = new System.IO.StreamReader(FilePost. PostedFile.InputStream); txtOutput.Value = tr.ReadToEnd(); } } }
Member of System.Web.UI.HtmlControls.
Assembly: System.Web.dll.
The HtmlInputHidden class encapsulates the <input type=hidden> tag. This can be used to put hidden text into the body of a form.
NOTE
In Web programming, it was common to use a <hidden> control to retain state information from one page reload to the next . It's not as common to use the HtmlInputHidden control for this purpose in ASP.NET because you have so many other options for state management. For example, you might want to use the State bag provided by the ViewState property of the Page object instead.
Properties | ||
---|---|---|
Attributes | ClientID | Controls |
Disabled | EnableViewState | ID |
Name | NamingContainer | Page |
Parent | Site | Style |
TagName | TemplateSourceDirectory | Type |
UniqueID | Value | Visible |
Methods | ||
DataBind | Dispose | Equals |
FindControl | GetHashCode | GetType |
HasControls | RenderControl | ResolveUrl |
ToString | ||
Events | ||
DataBinding | Disposed | Init |
Load | PreRender | ServerChange |
Unload |
Listing 2.22 shows an example of using an HtmlInputHidden object to submit additional information along with the form. In this example, you want the form to send the date and time the user accessed the page along with the data the user enters. The hidden control stores and submits this additional information.
<%@ Page language='C#' debug='true' trace='false' %> <script runat='server'> void Page_Load(Object Sender, EventArgs e) { if(!Page.IsPostBack) CreationDate.Value = DateTime.Now.ToString(); } void btnSubmit_Click(Object Sender, EventArgs e) { spnResult.InnerHtml = "This account was created on " + CreationDate.Value; } </script> <html> <head> <title>ASP.NET Page</title> </head> <body bgcolor="#FFFFFF" text="#000000"> <form runat='server'> Your Name: <input type="text" id="txtValue" value="Jeffrey" runat='server' NAME="txtValue"> <input type='submit' id="btnSubmit" OnServerClick='btnSubmit_Click' value="Create" runat='server' NAME="btnSubmit"> <br> Your Address: <input type="text" name="txtAddress" value="4905 Brown Valley Lane"> <input type="hidden" id="CreationDate" runat='server' NAME="CreationDate"> </form> <span id='spnResult' runat='server'></span> </body> </html>
In this code, the current date and time is stored in the hidden control when the page is loaded. When the form is submitted to the server, the value of the date stored in the hidden field is sent to the server where it can be utilized in code. In this case, the date is simply displayed, but you could incorporate it into database insertions and so forth.
There are several alternate ways you can hide information on the page the way a hidden control does. For example, most server controls have a Visible property. Setting this property to false hides the control, enabling you to assign data to the control without the data displaying on the page.
Note that "hiding" information by assigning it to an HtmlInputHidden control doesn't actually prevent the user from accessing the information; if you view the page's source in the browser, it's easy to see the value of the hidden control. It's even conceivable that a user could change the value of the hidden control. For this reason, be careful when using hidden controls to store certain types of sensitive information in your Web applications.
For other non-visible controls, the information contained within them is not sent to the browser. Instead it is stored in ViewState. HtmlInputHidden is the one exception to this.
Member of System.Web.UI.HtmlControls.
Assembly: System.Web.dll.
The HtmlInputImage class encapsulates the <input type=image> tag. Use this tag when you want your button to look like something other than a button. You supply the image. The ServerClick method fires an action on the server.
Properties | ||
---|---|---|
Align | Alt | Attributes |
Border | CausesValidation | ClientID |
Controls | Disabled | EnableViewState |
ID | Name | NamingContainer |
Page | Parent | Site |
Src | Style | TagName |
TemplateSourceDirectory | Type | UniqueID |
Value | Visible | |
Methods | ||
DataBind | Dispose | Equals |
FindControl | GetHashCode | GetType |
HasControls | RenderControl | ResolveUrl |
ToString | ||
Events | ||
DataBinding | Disposed | Init |
Load | PreRender | ServerClick |
Unload |
Member of System.Web.UI.HtmlControls.
Assembly: System.Web.dll.
The HtmlInputRadioButton class encapsulates the <input type=radio> tag. You group radio buttons together to form a group by assigning the same Name property to each button. The user may select only one member of the group .
Properties | ||
---|---|---|
Attributes | Checked | ClientID |
Controls | Disabled | EnableViewState |
ID | Name | NamingContainer |
Page | Parent | Site |
Style | TagName | TemplateSourceDirectory |
Type | UniqueID | Value |
Visible | ||
Methods | ||
DataBind | Dispose | Equals |
FindControl | GetHashCode | GetType |
HasControls | RenderControl | ResolveUrl |
ToString | ||
Events | ||
DataBinding | Disposed | Init |
Load | PreRender | Unload |
Member of System.Web.UI.HtmlControls.
Assembly: System.Web.dll.
The HtmlInputText class encapsulates the <input type=text> tag. See Listings 2.16 and 2.17 for an example of this class in use.
Properties | ||
---|---|---|
Attributes | ClientID | Controls |
Disabled | EnableViewState | ID |
MaxLength | Name | NamingContainer |
Page | Parent | Site |
Size | Style | TagName |
TemplateSourceDirectory | Type | UniqueID |
Value | Visible | |
Methods | ||
DataBind | Dispose | Equals |
FindControl | GetHashCode | GetType |
HasControls | RenderControl | ResolveUrl |
ToString | ||
Events | ||
DataBinding | Disposed | Init |
Load | PreRender | ServerChange |
Unload |
Member of System.Web.UI.HtmlControls.
Assembly: System.Web.dll.
The HtmlSelect class is the ASP.NET HTML control abstraction of the HTML SELECT element. You can set the Multiple property to true to enable the user to select multiple items in the list. The Items collection contains the items. Use <controlname>.Items[<controlname>.SelectedIndex].Value to get the selected items value. See Listing 2.9 for the HtmlSelect class in action.
Properties | ||
---|---|---|
Attributes | ClientID | Controls |
DataMember | DataSource | DataTextField |
DataValueField | Disabled | EnableViewState |
ID | InnerHtml | InnerText |
Items | Multiple | Name |
NamingContainer | Page | Parent |
SelectedIndex | Site | Size |
Style | TagName | TemplateSourceDirectory |
UniqueID | Value | Visible |
Methods | ||
DataBind | Dispose | Equals |
FindControl | GetHashCode | GetType |
HasControls | RenderControl | ResolveUrl |
ToString | ||
Events | ||
DataBinding | Disposed | Init |
Load | PreRender | ServerChange |
Unload |
Member of System.Web.UI.HtmlControls.
Assembly: System.Web.dll.
The HtmlTable class encapsulates the <table> tag. The Rows property returns a collection of all the <TR> tags in the table.
Properties | ||
---|---|---|
Align | Attributes | BgColor |
Border | BorderColor | CellPadding |
CellSpacing | ClientID | Controls |
Disabled | EnableViewState | Height |
ID | InnerHtml | InnerText |
NamingContainer | Page | Parent |
Rows | Site | Style |
TagName | TemplateSourceDirectory | UniqueID |
Visible | Width | |
Methods | ||
DataBind | Dispose | Equals |
FindControl | GetHashCode | GetType |
HasControls | RenderControl | ResolveUrl |
ToString | ||
Events | ||
DataBinding | Disposed | Init |
Load | PreRender | Unload |
Member of System.Web.UI.HtmlControls.
Assembly: System.Web.dll.
The HtmlTableCell class encapsulates the individual cells in an HtmlTableRow. The ColSpan and RowSpan properties can be used to span a number of columns or rows, respectively. The NoWrap property can be used to indicate that a cell shouldn't wrap. The Align and VAlign properties can be used to control alignment.
Properties | ||
---|---|---|
Align | Attributes | BgColor |
BorderColor | ClientID | ColSpan |
Controls | Disabled | EnableViewState |
Height | ID | InnerHtml |
InnerText | NamingContainer | NoWrap |
Page | Parent | RowSpan |
Site | Style | TagName |
TemplateSourceDirectory | UniqueID | VAlign |
Visible | Width | |
Methods | ||
DataBind | Dispose | Equals |
FindControl | GetHashCode | GetType |
HasControls | RenderControl | ResolveUrl |
ToString | ||
Events | ||
DataBinding | Disposed | Init |
Load | PreRender | Unload |
Member of System.Web.UI.HtmlControls.
Assembly: System.Web.dll.
This class represents a collection of all HtmlTableCells within an HtmlTable control.
Properties | ||
---|---|---|
Count | IsReadOnly | IsSynchronized |
Item | SyncRoot | |
Methods | ||
Add | Clear | CopyTo |
Equals | GetEnumerator | GetHashCode |
GetType | Insert | Remove |
RemoveAt | ToString |
Member of System.Web.UI.HtmlControls.
Assembly: System.Web.dll.
The HtmlTableRow class encapsulates a <tr> tag.
Properties | ||
---|---|---|
Align | Attributes | BgColor |
BorderColor | Cells | ClientID |
Controls | Disabled | EnableViewSTate |
Height | ID | InnerHtml |
InnerText | NamingContainer | Page |
Parent | Site | Style |
TagName | TemplateSourceDirectory | UniqueID |
VAlign | Visible | |
Methods | ||
DataBind | Dispose | Equals |
FindControl | GetHashCode | GetType |
HasControls | RenderControl | ResolveUrl |
ToString | ||
Events | ||
DataBinding | Disposed | Init |
Load | PreRender | Unload |
Member of System.Web.UI.HtmlControls.
Assembly: System.Web.dll.
A collection of the table rows inside the HtmlTable control.
Properties | ||
---|---|---|
Count | IsReadOnly | IsSynchronized |
Item | SyncRoot | |
Methods | ||
Add | Clear | CopyTo |
Equals | GetEnumerator | GetHashCode |
GetType | Insert | Remove |
RemoveAt | ToString |
Member of System.Web.UI.HtmlControls.
Assembly: System.Web.dll.
The HtmlTextArea class encapsulates the <textarea> tag. The Rows and Cols properties can be used to dynamically size the control. See Listing 2.20 for an example of the HtmlTextArea control in action.
Properties | ||
---|---|---|
Attributes | ClientID | Cols |
Controls | Disabled | EnableViewState |
ID | InnerHtml | InnerText |
Name | NamingContainer | Page |
Parent | Rows | Site |
Style | TagName | TemplateSourceDirectory |
UniqueID | Value | Visible |
Methods | ||
DataBind | Dispose | Equals |
FindControl | GetHashCode | GetType |
HasControls | RenderControl | ResolveUrl |
ToString | ||
Events | ||
DataBinding | Disposed | Init |
Load | PreRender | ServerChange |
Unload |
for RuBoard |