ASP.NET - TextBox 컨트롤
- 이전 페이지 WebForms ViewState
- 다음 페이지 WebForms 버튼
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 컨트롤의 값을 변경하여 폼을 제출할 수 있습니다.
아래의 예제에서는 .aspx 파일에서 TextBox 컨트롤, Button 컨트롤, Label 컨트롤을 선언했습니다. 제출 버튼이 트리거될 때, 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"> 이름을 입력하세요: <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>
아래의 예제에서, 우리는 .aspx 파일에서 TextBox 컨트롤과 Label 컨트롤을 선언했습니다. 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"> 이름을 입력하세요: <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 버튼