Asp.net TextBox control clearing method

Source: Internet
Author: User

TextBox

1. How to disable the default context menu of TextBox (right-click menu)

TextBox1.ContextMenu = new ContextMenu ();

See original

4. How to put the focus at the end of the TextBox text when the textBox gets the focus

TextBox1.SelectionStart = textBox1.Text. Length;


For textbox operations

In Asp.net, all TextBox content on the page is cleared at one time. Because TextBox is displayed on the client in the form of <input type = "text">, therefore, there are two solutions: client and server. Two solutions are available on the server! This article has been widely used in asp tutorials. net interview questions (I feel quite deep ).

 

1 foreach (Control c in this. FindControl ("form1"). Controls)
2 {
3 if (c is TextBox)
4 {
5 (TextBox) c). Text = "";
6}
7}
 8
 9
10
 

 

Code
1 FieldInfo [] infos = GetType (). GetFields (BindingFlags. Public | BindingFlags. NonPublic | BindingFlags. GetField | BindingFlags. Instance );
2 for (int I = 0; I <infos. Length; I ++)
3 {
4 if (infos [I]. FieldType = typeof (TextBox ))
5 {
6 (TextBox) infos [I]. GetValue (this). Text = "";
7}
8}


 

Brief Introduction
TextBox control
The TextBox control is used to create a TextBox that allows users to enter text.

The properties of the TextBox control are listed in our TextBox control Reference Manual.

The following example demonstrates some attributes that you may use in the TextBox control:

TIY

<Html>
<Body>

<Form runat = "server">

A basic TextBox:
<Asp: TextBox id = "tb1" runat = "server"/>
<Br/>

A password TextBox:
<Asp: TextBox id = "tb2" TextMode = "password" runat = "server"/>
<Br/>

A TextBox with text:
<Asp: TextBox id = "tb4" Text = "Hello World! "Runat =" server "/>
<Br/>

A multiline TextBox:
<Asp: TextBox id = "Int32" TextMode = "multiline" runat = "server"/>
<Br/>

A TextBox with height:
<Asp: TextBox id = "tb6" rows = "5" TextMode = "multiline"
Runat = "server"/>
<Br/>

A TextBox with width:
<Asp: TextBox id = "tb5" columns = "30" runat = "server"/>

</Form>

</Body>
</Html>

When a form is submitted, the content and settings of the TextBox control can be modified using a server script. You can click a button or when you change the value in the TextBox control to submit the form.

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.