ASP.NET - TextBox ควบคุม
- หน้าก่อนหน้า WebForms ViewState
- หน้าต่อไป WebForms Button
TextBox ควบคุม
TextBox ควบคุม
TextBox ควบคุม
TextBox ควบคุม TextBox ควบคุมTextBox ควบคุม
ตัวอย่างด้านล่างนี้แสดงรายละเอียดของคุณภาพที่คุณอาจจะใช้ในเครื่องมือควบคุม TextBox:
<html> <body> <form runat="server"> TextBox ธรรมดา: <asp:TextBox id="tb1" runat="server" /> <br /><br /> TextBox ซึ่งมีข้อความลับ: <asp:TextBox id="tb2" TextMode="password" runat="server" /> <br /><br /> TextBox ซึ่งมีข้อความ: <asp:TextBox id="tb4" Text="Hello World!" runat="server" /> <br /><br /> TextBox ซึ่งมีข้อความหลายแถว: <asp:TextBox id="tb3" TextMode="multiline" runat="server" /> <br /><br /> TextBox ซึ่งมีความสูง: <asp:TextBox id="tb6" rows="5" TextMode="multiline" runat="server" /> <br /><br /> TextBox ซึ่งมีความกว้าง: <asp:TextBox id="tb5" columns="30" runat="server" /> </form> </body> </html>
เพิ่มสคริปต์
เมื่อฟอร์มถูกส่งไป ข้อความและการตั้งค่าของเครื่องมือควบคุม TextBox สามารถถูกเปลี่ยนแปลงด้วยโปรแกรมบนเซิร์ฟเวอร์ สามารถส่งฟอร์มด้วยการกดปุ่มหรือเมื่อผู้ใช้เปลี่ยนค่าในเครื่องมือควบคุม TextBox:
ในตัวอย่างด้านล่างนี้ เราได้ประกาศ TextBox ซึ่งเป็นเครื่องมือควบคุม 1 ตัว Button ซึ่งเป็นเครื่องมือควบคุม 1 ตัว และ Label ซึ่งเป็นเครื่องมือควบคุม 1 ตัว ในไฟล์ .aspx จากนั้น เมื่อปุ่มส่งไปด้วยประสาทจะถูกกดลง หน่วยงาน submit จะถูกปฏิบัติการsubmit ซึ่งจะเขียนข้อความลงในเครื่องมือควบคุม Label:
<script runat="server"> Sub submit(sender As Object, e As EventArgs) lbl1.Text="Your name is " & txt1.Text End Sub </script> <html> <body> <form runat="server"> Enter your name: <asp:TextBox id="txt1" runat="server" /> <asp:Button OnClick="submit" Text="Submit" runat="server" /> <p><asp:Label id="lbl1" runat="server" /></p> </form> </body> </html>
ในตัวอย่างข้างต้น เราได้ประกาศ TextBox ควบคุมและ Label ควบคุมในไฟล์ .aspx ของเรา เมื่อคุณเปลี่ยนค่าใน TextBox และคลิกนอก TextBox จะมีการปฎิบัติ change มีขึ้น หน่วยงาน change จะเขียนข้อความลงในควบคุม Label:
<script runat="server"> Sub change(sender As Object, e As EventArgs) lbl1.Text="You changed text to " & txt1.Text End Sub </script> <html> <body> <form runat="server"> Enter your name: <asp:TextBox id="txt1" runat="server" text="Hello World!" ontextchanged="change" autopostback="true"/> <p><asp:Label id="lbl1" runat="server" /></p> </form> </body> </html>
- หน้าก่อนหน้า WebForms ViewState
- หน้าต่อไป WebForms Button