Intimate contact asp.net (4) Web control

Source: Internet
Author: User
Tags bind

Web Controls
According to the plan we're going to talk about Web controls for a while, I don't know how to define this Web control, it's harder to understand than HTML controls, and HTML is so much like the old familiar stuff. And the Web controls are quite different from what we normally see, I do not know if you remember the words I said, that is, ASP.net's program is like writing a window in the VBVC, the first of these windows to add the controls we need, and then the controls to operate. If you've learned a little bit of VBVC programming, it's not difficult to understand this, and the Web controls in asp.net are like controls in VBVC. Let's put these controls on the page and then control them through Page_Load and other custom events. Let's look at an example to find out. Let's start with a simple label control. The source code is as follows:

<% @ Page language= "C #"%>
<% @ Import namespace= "System.Data"%>
<script language= "C #" runat= "Server" >
public void Page_Load (Object Src,eventargs E)
{
if (! Page.IsPostBack)
{
Label3. Text= "This is a bold word, and underlined";
}
}
</script>
<title> Test Label Controls </title>
<body>
<bold> Test Label Control:<br></bold>
<asp:label id= "Label1" font-size= "9pt" font-bold= "true" forecolor= "Red" runat= "Server" > This is red bold text </asp: Label><br>
<asp:label id= "Label2" font-size= "10pt" font-italic= "true" forecolor= "Blue" runat= "Server" text= "This is the Blue italic text"/> <br>
<asp:label id= "Label3" font-size= "11pt" font-underline= "true" runat= "Server"/>

</body>

The result of this procedure is

To test the Label control:
This is a bold red text.
This is the Blue italic text
This is a bold word and underlined

Look at the source code, and then see the results of the program execution is not found in the label control and VB in the label control is very similar:

(Note: You see on your machine Chinese may be garbled, then please open the x:\winnt\microsoft\framework\v1.0.224 directory, find the Config.web file, open it, find the following text:

<globalization
Requestencoding= "Iso-8859-1"
Responseencoding= "Iso-8859-1"
/>

Change the iso-8859-1 to Gb2312,ok, then execute the program, Chinese is not out:

Here we have three ways to manipulate the label control, the first is an HTML-like closed tag, the word to be written between <asp:Label></asp:Label>, the second is to use the Label control Text property; is to write text into a label control by executing the Page_Load event. These three methods are very useful, see your own favorite, the third is the most commonly used, we will often use. The label control not only has the Text property to control its text, but also font-size properties to control the font size, color and other attributes, here's an example I have used, we have a good look, I believe there is no problem

We have seen the operation of the label control, so we have a perceptual understanding of the Web control, in ASP.net, a total of 28 Web controls, which are:

AdRotator Button Calendar CheckBox
CheckBoxList CompareValidator CustomValidator DataGrid
DataList DropDownList HyperLink Image
ImageButton Label LinkButton ListBox
Panel RadioButton RadioButtonList RangeValidator
RegularExpressionValidator Repeater RequiredFieldValidator Table
TableCell TableRow TextBox ValidationSummary

You can go to my last section of the site to see the specific use of their own, here I would like to talk about Datagrid,datalit,listbox but they all need to use binding knowledge (which we will speak in the next section), So let's take a look at the use of DropDownList (because our last section uses a select to explain HTML controls)

Let's look at one example:

<% @ Page language= "C #"%>
<% @ Import namespace= "System.Data"%>
<script language= "C #" runat= "Server" >
public void Page_Load (Object Src,eventargs E)
{

}
public void Sub_click (Object Sender,eventargs e)
{
String Chioce;
Chioce=ddl. Selecteditem.text;
Show. text= "You choose the <font color=red> of the studio" +chioce+ "</font> members";
}
</script>
<title></title>
<body>
<form runat= "Server" >
Please select the aspcn.com Studio staff:<br>
<asp:dropdownlist id= "DDL" runat= "Server" >
<asp:ListItem> Flying Knives </asp:ListItem>
<asp:ListItem> Gale </asp:ListItem>
<asp:ListItem>Zsir</asp:ListItem>
<asp:ListItem> Pudding </asp:ListItem>
<asp:ListItem> Asia Hao </asp:ListItem>
</asp:DropDownList>
<br>
<asp:button id= "Sub" text= "Submit" runat= "Server"/><br>
<asp:label id= "Show" runat= "Server"/>
</form>
</body>

It performs the display as:

Please select the aspcn.com Studio staff:

FlyingWindZsirPuddingJahau

If I select one of the flying knives, and then press the "Submit" button, then the display is:

Please select the aspcn.com Studio staff:

FlyingWindZsirPuddingJahau

You selected a flying member of this studio

DropDownList control, in fact, and select almost, function is a little bit more, but this more a little bit of function is very useful, this is our next verse to learn the bind, oh, is not want to learn: not urgent, we first analyze the procedures here. We use the DropDownList control to build a list of lists, and then we select one of the options and then submit the Submit key. Here we can see that the handler is Sub_click this event, which is fired by the button control named Sub, and the event used is onclick, where the OnServerClick events used by the HTML control are different, and we need to be clear. The others seem to have nothing to say. Oh

We'll talk about bind in the next verse, which is very important.



Related Article

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.