HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
Server controls are tags understood by the server.
Codes listed below are copied from the previous chapter:
The above code reflects the limitations of classic ASP: The code block must be placed where you want the output to appear.
Through classic ASP, want to separate executable code from the HTML page is not possible. This makes the page difficult to read, it is difficult to maintain.
By ASP.NET server controls, it has solved the above-mentioned "spaghetti code" problem.
Server controls are tags understood by the server.
There are three types of server controls:
HTML server controls are HTML tags understood by the server.
ASP.NET file HTML elements, the default is treated as text. To get these elements programmable, add runat = "server" attribute to the HTML element. This attribute indicates that the element will be treated as a server control. Also you need to add the id attribute to identify the server control. id reference can be used to operate the server control at run time.
Note: All HTML server controls must be located within with runat = "server" attribute of the <form> tag.runat = "server" attribute indicates that the form must be processed on the server. It also shows that the controls contained within it can be accessed by server scripts.
In the following example, we declare a HtmlAnchor server control in an x file. Then we operate HRef property HtmlAnchor control in an event handler (an event handler for a given event code execution subroutine) in. ASP.NET Page_Load event is understandable in a variety of events:
Executable code itself has been moved outside the HTML.
Web server controls are special ASP.NET tags understood by the server.
Like HTML server controls, Web server controls are also created on the server, and they also need runat = "server" attribute to take effect. However, Web server controls do not need to map any existing HTML elements and they may represent more complex elements.
Create a Web server control syntax is:
In the following example, we declare a Button server control in an x file. Then we create an event handler for the Click event to change the text on the button:
Validation server controls are used to validate user input. If the user input is not validated, an error message will be displayed to the user.
Each validation control performs one of the specified type of authentication (such as verification of a specified value or a range of values).
By default, when a Button, ImageButton, LinkButton control is clicked, the page performs validation. You can set the CausesValidation to false, the button controls to prevent verification is clicked.
Create a Validation server control syntax is:
In the following example, we declared in the x file in a TextBox control, a Button control, a RangeValidator control. "! The value must be from 1 to 100" If the validation fails, the text will be displayed in RangeValidator control: