Course ASP.NET : forms and server controls
HTML Forms
HTML Form Controls
The traditional HTML form supports several controls, and tag is the most common that is used to define text boxes, radio buttons, check boxes, buttons, submit button, reset button, password fields, and hidden fields.
Input
|
|
Creates form elements such as text and password boxes,
hidden fields, radio buttons, check boxes, submit and reset buttons, images,
and buttons
|
Select
|
|
Creates elements such as a drop-down list and a list
box
|
Textarea
|
|
Creates a multilane text box in a form |
The tag has four attributes that are commonly used:
·
name
– is used to identify the control.
·
type
– specifies the type of form control: text, radio, checkbox, etc.
·
value
– can be used to define a default value.
· checked – used to pre-select a radio control.
ASP.NET Forms
ASP.NET has a form tag and associated controls that are used to process a Web page that contains user data. The ASP.NET version of the
................ ASP.NET codes
Thus, there is only one attribute (runat =”server”) and no files or methods are needed to process an ASP.NET form. This is because, as we will see, ASP.NET form controls are created in the Web server, and there is no reason to send them anymore from the browser.
Note: The form is always submitted to the page
itself. If you specify an action attribute, it is ignored. If you omit the
method attribute, it will be set to method="post" by default. Also,
if you do not specify the name and id attributes, they are automatically
assigned by ASP.NET. An .aspx page can only contain one
ASP.NET Server Controls
The ASP.Net server controls are used to
create ASP.NET forms. As we have said before, there are two kinds of server
controls:
·
HTML Server
Controls - Traditional HTML tags,
·
ASP.NET
Web Controls - New ASP .NET tags
HTML Server Controls:
HTML server controls are traditional HTML
tags with an added attribute,
runat="server". This attribute indicates that the element should be
treated as a server control.
<
input type = “text” runat = “server” />
Note: All HTML server controls must be within a
ASP.NET Web Controls:
Like HTML server controls, ASP.NET controls are also created on
the server and they require a runat="server" attribute to work.
However, these controls do not necessarily map to any existing HTML elements
and they may represent more complex elements.
The syntax for creating an ASP.NET server control is:
Example:
In the following example we declare a Button
server control in an .aspx file. Then we create an event handler for the Click
event which changes the text on the button......
0 commentaires: