Autopostback and autocomplete Introduction

Source: Internet
Author: User
1. By default, the autopostback value is false. When the value is true, as long as the content of the textbox changes, the form containing the Textbox Control will be automatically uploaded back to the server. For example Code The 1 page contains a simple search form. If the textbox content is changed and the focus is removed from the Textbox Control, the form is automatically sent back to the server and the textbox content is displayed.

<% @ Page Language = "C #" %>
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<SCRIPT runat = "server">

Protected void txtsearch_textchanged (Object sender, eventargs E)
{
Lblsearchresults. Text = "Search for:" + txtsearch. text;
}
</SCRIPT>
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head id = "head1" runat = "server">
<Title> textbox autopostback </title>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>

<Asp: Label
Id = "lblsearch"
TEXT = "Search :"
Runat = "server"/>
<Asp: textbox
Id = "txtsearch"
Autopostback = "true"
Ontextchanged = "txtsearch_textchanged"
Runat = "server"/>

<HR/>

<Asp: Label
Id = "lblsearchresults"
Runat = "server"/>

</Div>
</Form>
</Body>
</Html>

When the content of the textbox control changes, the processing event is triggered on the server side.
Note: Do not use the autopostback attribute. Creating a page that automatically returns data to the server can easily confuse those using secondary devices such as the screen reader. If it must be used, a tooltip attribute value should be used to notify users that the tool will be reloaded.

2. The Textbox Control also has an attribute that is used to associate a specific AutoComplete class. When AutoComplete is enabled, you do not need to repeat common information in the self-love form. If the browser AutoComplete is not disabled, the browser prompts the user to enter the same value as the previous one. (Even if you enter form fields in different websites) The Code is as follows:

<% @ Page Language = "C #" %>
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head id = "head1" runat = "server">
<Title> show AutoComplete </title>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>

<Asp: Label
Id = "lblfirstname"
TEXT = "First name :"
Associatedcontrolid = "txtfirstname"
Runat = "server"/>
<Br/>
<Asp: textbox
Id = "txtfirstname"
Autocompletetype = "firstname"
Runat = "server"/>
<Br/>
<Asp: Label
Id = "lbllastname"
TEXT = "Last Name :"
Associatedcontrolid = "txtlastname"
Runat = "server"/>
<Br/>
<Asp: textbox
Id = "txtlastname"
Autocompletetype = "lastname"
Runat = "server"/>
<Br/>
<Asp: button
Id = "btnsubmit"
TEXT = "Submit"
Runat = "server"/>

</Div>
</Form>
</Body>
</Html>

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.