아이디와암호를입력관련예제입니다.
Display="Dynamic" : 공간을잡지않음 (공간이없고텍스트만출력하고싶을때사용)
Display="Static" : 고정됨
FrmRequiredFieldValidator.aspx |
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> 입력 확인 유효성 검사 컨트롤<br /><br />
아이디 : <asp:TextBox ID="txtUserID" runat="server"></asp:TextBox> [<asp:RequiredFieldValidator ID="valUserID" runat="server" ControlToValidate="txtUserID" ValidationGroup="Login" Display="Dynamic" ErrorMessage="아이디를 입력하시오."></asp:RequiredFieldValidator> ]<br />
암호 : <asp:TextBox ID="txtPassword" runat="server"></asp:TextBox> [<asp:RequiredFieldValidator ID="valPassword" runat="server" ControlToValidate="txtPassword" ValidationGroup="Login" Display="Static" ErrorMessage="암호를 입력하시오."></asp:RequiredFieldValidator> ]<br /><br />
<asp:Button ID="btnLogin" runat="server" Text="로그인" ValidationGroup="Login" />
<asp:Button ID="Button1" runat="server" Text="다시입력" onclick="Button1_Click" />
</div> </form> </body> </html> |
FrmRequiredFieldValidator.aspx.cs |
protected void Button1_Click(object sender, EventArgs e) { txtUserID.Text = txtPassword.Text = "1"; } |
결과화면 |
[그림30-1] |
RequiredFieldValidator 컨트롤을 자바스크립트로 표현 |
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script type="text/javascript"> function CheckLogin() { var userId = document.getElementById("txtUserID"); if (userId.value == "") { alert("아이디를 입력하시오."); userId.focus(); userId.select(); } else { alert("아이디 : " + userId.value); } } </script> </head> <body>
<form> 아이디 : <input type="text" name="txtUserID" id="txtUserID" /><br />
<input type="button" value="로그인" onclick="CheckLogin()" /> </form>
</body> </html> |
'ASP.NET' 카테고리의 다른 글
32.C# ASP.NET - CompareValidator [ 유효성검사컨트롤 ] (0) | 2009.10.13 |
---|---|
31.C# ASP.NET - RangeValidator [ 유효성검사컨트롤 ] (0) | 2009.10.13 |
17.ASP.NET - 자료실 게시판(9) : Down.aspx (0) | 2009.10.12 |
16.ASP.NET - 자료실 게시판(9) : List.aspx (2) | 2009.10.12 |
15.ASP.NET - 자료실 게시판(8) : Write.aspx (0) | 2009.10.12 |
Comments