Introduction

Server Controls are the tags that are understood by the server. There are basically three types of server controls.

ASP.NET HTML Server Controls

ASP.NET provides a way to work with HTML Server controls on the server side; programming with a set of controls collectively is called HTML Controls.

Note:

All HTML server controls must be within a <form> tag with the runat="server" attribute. The runat="server" attribute indicates that the form should be processed on the server. It also indicates that the enclosed controls can be accessed by server scripts.

The System.Web.UI.HtmlControls.HtmlControl base class contains all of the common properties. HTML server controls derive from this class.

For example, consider the HTML input control:

htmlinput cntrl im.gif

The following table describes the HTML server controls:

html cntrls.gif

ASP.NET Web Server Controls

The syntax for creating a Web server control is:

web syntx.gif

The following table describes the WEB server controls:

wb ser cntrls.gif


ASP.NET Validation Server Controls

Some Server Validation controls are:

validations cntrl.gif

The syntax for creating a Validation server control is:

syntx validation.gif

Default.aspx Page

  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head runat="server">
  5. <title></title>
  6. </head>
  7. <body>
  8. <form id="form1" runat="server">
  9. <div style="width: 414px; background-color: #E6E6FA; height: 110px;">
  10. Name
  11. <asp:textbox id="TextBox1" runat="server" style="z-index: 1; left: 73px; top: 15px;
  12. position: absolute">
  13. </asp:textbox>
  14. <asp:requiredfieldvalidator id="RequiredFieldValidator1" runat="server" controltovalidate="TextBox1"
  15. errormessage="Cannot be Blank" setfocusonerror="True" style="position: absolute;
  16. z-index: 1; left: 238px; top: 21px">
  17. </asp:requiredfieldvalidator>
  18. <br />
  19. Mobile
  20. <asp:textbox id="TextBox2" runat="server" style="position: relative; top: 4px; left: 12px">
  21. </asp:textbox>
  22. <br />
  23. <tr>
  24. <td class="style3">
  25. Email
  26. </td>
  27. <td class="style2">
  28. <asp:regularexpressionvalidator id="remail" runat="server" controltovalidate="txtemail"
  29. errormessage="Enter in proper format" validationexpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
  30. style="z-index: 1; left: 279px; top: 61px; position: absolute">
  31. </asp:regularexpressionvalidator>
  32. <asp:textbox id="txtemail" runat="server" width="200px" style="z-index: 1; left: 73px;
  33. top: 62px; position: absolute">
  34. </asp:textbox>
  35. </td>
  36. <td>
  37. </td>
  38. </tr>
  39. <asp:button id="Button1" runat="server" text="SUBMIT" style="z-index: 1; left: 73px;
  40. top: 91px; position: absolute; right: 1066px" />
  41. <br />
  42. <br />
  43. </div>
  44. </form>
  45. </body>
  46. </html>

Output

output vald.gif

If any input field is left blank then it is handled by the control name as RequiredField Validation control.

name valid.gif

It ensures that the value of an input control matches a specified pattern and this is handled by the RegularExpression Validation control.

email valid.gif