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>
|