The third day of the 10 day society asp.net

Source: Internet
Author: User
asp.net learning Purpose: Mastering the use of Web controls (i)

You might ask, why do you need a Web control? Web control room is like the control room in VB, can be referenced anywhere in the program, modify all attributes, with its cooperation to complete the code separation. Think about it, if the previous HTML control room, we when we need to display a section of the database in a certain place is not only with <%=%> this is bound to include the code block in the HTML program, the separation of code and interface purposes.
Perhaps you will also ask, why do you want code to separate that? The reason is very simple, not every programmer is a qualified web designer, if we need to modify the code will destroy the original design of the Web designer, is not convenient, the program code and HTML code mixed together for programmers is also inconvenient to modify the code. Of course, our web designers also need to learn a little bit about Web control.
Here is an introduction:
One, Label control:
Main properties:
Text label display
Example: <asp:label id= "lblmessage" text= "AAA" runat= "Server"/>
Note that we cannot omit runat= "server" and that all Web controls are included in the <form runat= "Server" ></form> Center
Here is a complete example, modify the label's Text property in the program to change the display of the page.

<script runat= "Server" language= "C #" >
void Page_Load ()
{
lblmessage.text= "Hello world!";
}
</script>
<body>
<form runat= "Server" >
<asp:label id= "lblmessage" runat= "Server"/>
</form>
</body>



--------------------------------------------------------------------------------


<script runat= "Server" Language= "VB" >
Sub Page_Load
lblmessage.text= "Hello world!"
End Sub
</script>
<body>
<form runat= "Server" >
<asp:label id= "lblmessage" runat= "Server"/>
</form>
</body>

Second, TextBox control:
Main properties:
The text displayed by the text control;
MaxLength text box can be added to the maximum number of characters (multiple lines of text box is not valid);
ReadOnly Read only;
TextMode has the following valid values Multiline,password,singleline;
Rows Specify the vertical dimensions of the text box

Third, Button control:
There are three types: button-standard form buttons, ImageButton to display images, LinkButton display as hyperlinks button
button is basically the Text property to set the text above the buttons;
ImageButton is basically imageurl to set the address of the image on the button, alternativetext the text displayed when the browser does not support the picture;
LinkButton is basically the Text property to set the text on the button;
The common attribute of the three is causesvalidation=true/false to set the button to submit the form is not checked (later on the validation control)
The common approach of the three is that onclick is the function that triggers when the button is clicked, and here's an example:

<script runat= "Server" language= "C #" >
void Btncounter_onclick (Object Sender,eventargs e)
{
Btncounter.text= "clicked";
}
</script>
<body>
<form runat= "Server" >
<asp:button text= "unclicked" onclick= "Btncounter_onclick" id= "Btncounter" runat= "Server"/>
</form>
</body>



--------------------------------------------------------------------------------


<script runat= "Server" Language= "VB" >
Sub Btn_counter_onclick (S as object,e as EventArgs)
btncounter.text= "Clicked"
End Sub
</script>
<body>
<form runat= "Server" >
<asp:button text= "unclicked" onclick= "Btncounter_onclick" id= "Btncounter" runat= "Server"/>
</form>
</body>

Say these three controls today, continue tomorrow.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.