Day 3
Objective: To learn how to use WEB controls (1)
Maybe you will ask, why do you need WEB controls? The WEB control room is like the control room in VB. It can be referenced anywhere in the program, and all attributes can be modified. With its cooperation, code separation can be completed. Think about it. If it is still the previous HTML console, when we need to display the content of a database in a certain place, do we only use <% = %> to include the code block of the program in HTML, the purpose of code separation and interface separation is not achieved.
Maybe you will ask why do you need code separation? The reason is very simple. Not every programmer is a qualified web designer. If we need to modify the code, it will damage the original settings of the web designer. Isn't it inconvenient, the combination of program code and HTML code is not convenient for programmers to modify the code. Of course, our WEB designers also need to learn a little knowledge about WEB control.
Here is an introduction:
1. Label control:
Main attributes:
Text displayed by the Text Tab
Example: <asp: Label id = "lblMessage" Text = "aaa" runat = "server"/>
Note that the runat = "server" cannot be omitted, and all WEB controls must be included in the <form runat = "server"> </form>
The following is a complete example. Modify the Text attribute of the Label in the program to change the display of the webpage.
<Script runat = "server" language = "c #">
Void Page_Load ()
{
LblMessage. Text = "Hello World! ";
}
</Script>
<Html>
<Head> <title> Label. aspx </title> <Body>
<Form runat = "server">
<Asp: Label id = "lblMessage" runat = "server"/>
</Form>
</Body>
</Html>
<Script runat = "server" language = "vb">
Sub Page_Load
LblMessage. Text = "Hello World! "
End sub
</Script>
<Html>
<Head> <title> Label. aspx </title> <Body>
<Form runat = "server">
<Asp: Label id = "lblMessage" runat = "server"/>
</Form>
</Body>
</Html>
2. TextBox Control:
Main attributes:
Text displayed by the Text control;
Maximum number of characters that can be added to the MaxLength text box (invalid multi-line text box );
ReadOnly;
TextMode has the following valid values: MultiLine, Password, SingleLine;
Rows specifies the vertical size of the text box
3. Button control:
There are three types of buttons: Standard Form buttons, form buttons for ImageButton to display images, and LinkButton to display images as hyperlinks.
The Button is basically the Text attribute to set the Text above the Button;
ImageButton is basically the image URL used to set the button image address; AlternativeText displays text when the browser does not support images;
The LinkButton is basically the Text attribute used to set the Text on the button;
The common attribute of the three is CausesValidation = true/false to set whether the form submitted by the button is verified (the validation control will be discussed later)
In common, OnClick is the function triggered when a button is clicked. The following is an example:
<Script runat = "server" language = "c #">
Void btnCounter_OnClick (object sender, EventArgs e)
{
BtnCounter. Text = "Clicked ";
}
</Script>
<Html>
<Head> <title> Label. aspx </title> <Body>
<Form runat = "server">
<Asp: Button Text = "UnClicked" OnClick = "btnCounter_OnClick" id = "btnCounter" runat = "server"/>
</Form>
</Body>
</Html>
<Script runat = "server" language = "vb">
Sub btn_COunter_OnClick (s as object, e as eventargs)
BtnCounter. Text = "Clicked"
End sub
</Script>
<Html>
<Head> <title> Label. aspx </title> <Body>
<Form runat = "server">
<Asp: Button Text = "UnClicked" OnClick = "btnCounter_OnClick" id = "btnCounter" runat = "server"/>
</Form>
</Body>
</Html>
Let's talk about these three controls today and continue tomorrow.