C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
ASP.NET HTML Server ControlsHTML server controls are HTML elements that contain attributes to accessible at server side. By default, HTML elements on an ASP.NET Web page are not available to the server. These components are treated as simple text and pass through to the browser. We can convert an HTML element to server control by adding a runat="server" and an id attribute to the component. Now, we can easily access it at code behind. Example <input id="UserName" type="text" size="50"runat="server" /> All the HTML Server controls can be accessed through the Request object. HTML ComponentsThe following table contains commonly used HTML components.
ExampleHere, we are implementing an HTML server control in the form. // htmlcontrolsexample.aspx <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="htmlcontrolsexample.aspx.cs" Inherits="asp.netexample.htmlcontrolsexample" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <input id="Text1" type="text" runat="server"/> <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click"/> </div> </form> </body> </html> This application contains a code behind file. // 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); } } } Output: When we click the button after entering text, it responses back to client.
Next TopicASP.NET CompareValidator
|