asp 페이지의 asp:textbox 에 힌트로 보여질 html5에서 사용되는 placeholder 에 해당하는 문자 나오게 하기.
컨트롤러에 placeholder 애튜리뷰트를 추가하기. (아래의 방법이 가장 간단한 방법)
<asp:textbox id="txtWithHint" placeholder="hint" runat="server"/>
<input type="text" placeholder="hint"/>
그외의 방법들도 소개합니다.
The placeholder
attribute
You're looking for the placeholder
attribute. Use it like any other attribute inside your ASP.net control:
<asp:textbox id="txtWithHint" placeholder="hint" runat="server"/>
Don't bother about your IDE (i.e. Visual Studio) maybe not knowing the attribute. Attributes which are not registered with ASP.net are passed through and rendered as is. So the above code (basically) renders to:
<input type="text" placeholder="hint"/>
Using placeholder
in resources
A fine way of applying the hint to the control is using resources. This way you may have localized hints. Let's say you have an index.aspx file, your App_LocalResources/index.aspx.resx file contains
<data name="WithHint.placeholder">
<value>hint</value>
</data>
and your control looks like
<asp:textbox id="txtWithHint" meta:resourcekey="WithHint" runat="server"/>
the rendered result will look the same as the one in the chapter above.
Add attribute in code behind
Like any other attribute you can add the placeholder
to the AttributeCollection
:
txtWithHint.Attributes.Add("placeholder", "hint");
참고: https://stackoverflow.com/questions/15823983/how-do-i-put-hint-in-a-asptextbox
'C# > ASP.net' 카테고리의 다른 글
ASP.net DropDownList 값 선택하기, Select 선택값 변경시 함수 처리하기 (0) | 2021.01.28 |
---|---|
ASP.net 유효성 검사 CompareValidator / CauseValidation (0) | 2021.01.28 |
Mail 발송하기 예제 (System.Net.Mail) (0) | 2018.10.25 |
Visual Studio를 이용한 ASP.net 웹 배포:테스트 환경에 배포 (0) | 2018.09.26 |
URL중에 http://도메인:PORT 구하기 (0) | 2018.04.27 |
WCF Web HTTP Service Help Page만들기 (URI, Method-GET/POST등) (0) | 2017.10.06 |
DB Connection 실패시 나오는 에러 (방화벽이 차단했을경우등) SqlException (0x80131904) (0) | 2017.09.28 |
에러: Object cannot be cast form DBNull to other types. (0) | 2017.08.30 |
(로그인하지 않으셔도 가능)