Teaching Ideas server controls of ASP. NET: 1. Label, Textbox, hyperlink, and three button controls

Source: Internet
Author: User

In Asp.net, controls are mainly divided into HTML controls and server controls. Which type of controls are used on the page? With the deep learning and development experience, students will gradually become proficient, currently, server controls are frequently used in learning and are of the same usage as winform. to make a better transition, we will first teach server controls. First, let's start with the simplest label control.

The server control is inSource codeYou must use <asp: contolstype (control type: Label) id = "Control name" runat = "server" text = "control text"> control scope, for example, display bound data on the Control </ASP:>. If the control does not have a valid range, it can also be in the form of no closed elements, such as: <asp: contolstype (control type: Label) id = "Control name" runat = "server" text = "control text" contolstype (control type: Label)/>, this is an XHTML writing format.

LabelIn addition to labels, a widget can set its text attribute like in winform. It can also add hotkeys to pages, you can use Alt + hotkey to perform operations on the webpage. When setting hot keys for the control, avoid Alt + F, E, V, I, O, T, A, W, and H that have been used by IE. If these letters are used, the IE operation replaces the operation on the page.

TextboxYou need to remember the properties of the control and winform. The textmode text behavior mode has the following values: single-line Input text, multiline multi-line Input text, and password input text, when textbox supports multiple rows, you must modify the wrap attribute and change it to true. In this way, the input text can be automatically wrapped Based on the width of the text box, instead of entering a carriage return for line feed;AutocompletetypeThe Automatic completion function is added to the property to record the historical records that match the property value. When the value is none,TextboxControls that have the same ID attributes as those on different pagesTextboxControls share the list when its value isDisabled is deemed to have canceled the Automatic completion function..

HyperlinkThe widget displays a hyperlink on the page. You can set the navigateurl attribute to switch from a page to a page with the value of the navigateurl attribute, similar to the <A> tag, the value of the text attribute is set to the text of the hyperlink. For example

<Asp: hyperlink id = "hyperlink1" runat = "server" navigateurl = "~ /Default. aspx "> use the hyperlink control to implement hyperlinks </ASP: hyperlink>
<Asp: hyperlink id = "hyperlink2" runat = "server" navigateurl = "~ /Default. aspx "text =" Use the hyperlink control to implement hyperlinks "/>

ButtonControls are divided into three types on the Web: button (Standard Form button) and linkbutton (button control that displays hypertext links on the button) imagebutton (the button display method is to use an image). If you want to modify the display text on the button and linkbutton, the text attribute is also modified; the image path on imagebutton needs to be assigned to the imagurl attribute. The most important attribute in linkbutton is postbackurl. The value is the page address to which the page is redirected when you click linkbutton, the relative path and absolute path can be used for the same page address and image path,

Below, the students drag and drop two labels and two textbox controls in the toolbar. Three buttons are displayed on the page and configured as logon forms. The carriage return is not recognized on the page, therefore, the line feed between the user name and password can be found at the source of the page.CodeUse <br/> to implement line feed. Please try to change the password text box to the password format, set the text of the Standard button to "empty", and set the linkbutton text to "Enter Baidu ", when you click this button.

 

Layout Logon
1 <% @ Page Language = " C # " Autoeventwireup = " True " Codefile = " Default. aspx. CS " Inherits = " _ Default "   %>
2 <! Doctype HTML public " -// W3C // dtd xhtml 1.0 transitional // en "   " Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " >
3 < HTML xmlns = " Http://www.w3.org/1999/xhtml " >
4 < Head runat = " Server " >
5 < Title > No title page </ Title >
6 </ Head >
7 < Body >
8 < Form ID = " Form1 " Runat = " Server " >
9 < Div >
10 <! -- Acesskey is the shortcut key, and associatedcontrolid is the control to which the shortcut key is bound. Can you guess the words displayed on the label? -->
11 < ASP: Label ID = " Label1 " Runat = " Server " Text = " User name: " Accesskey = " Y "  
12 Associatedcontrolid = " Textbox1 " > User < U > N </ U > AME </ ASP: Label >
13 <! -- The autocompletetype attribute provides the auto-completion function. The value is 32. I use email. When
14 After filling in the text box, you will find that textbox1 contains all text in the form of email. -->
15 < ASP: textbox ID = " Textbox1 " Runat = " Server " Autocompletetype = " Email " > </ ASP: textbox >
16 < BR />  
17 < ASP: Label ID = " Label2 " Runat = " Server " Text = " Password: " Accesskey = " M "  
18 Associatedcontrolid = " Textbox2 " > < U > P </ U > Assword </ ASP: Label >
19 < ASP: textbox ID = " Textbox2 " Runat = " Server " Textmode = " Password " > </ ASP: textbox >
20 < BR />
21 <! -- The login button uses imagebutton. The image path is the relative path in the project folder. -->
22 < ASP: imagebutton ID = " Imagebutton1 " Runat = " Server " Imageurl = " ~ /Denglu.gif "   />
23 < ASP: button ID = " Button1 " Runat = " Server " Text = " Clear "   />
24 <! -- The connection button uses linkbutton. After clicking this button, the Baidu webpage is displayed. -->
25 < ASP: linkbutton ID = " Linkbutton1 " Runat = " Server " Postbackurl = " Http://www.baidu.com " > Enter Baidu search </ ASP: linkbutton >
26 </ Div >
27 </ Form >
28 </ Body >
29 </ Html >
30

The effect is as follows: Pay attention to the modified autocompletetype attribute in textbox1.

 

I will explain the common control usage in the C # statement for implementing specific functions in specific code!

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.