CheckBox에 따라 asp.TextBox/Input을 활성화/비활성화해야합니다. CheckBox.Checked = true이면 asp.TextBox/Input을 활성화하거나 CheckBox.Checked = false 인 경우 asp.TextBox/Input을 비활성화해야합니다.CheckBox.Checked를 기반으로 asp : TextBox 컨트롤을 활성화/비활성화합니다.
아래 코드는 첫 번째 클릭에서만 작동합니다. 즉, 상자를 선택하면 asp.TextBox/Input을 활성화하지만 asp.TextBox/Input을 선택 취소해도 선택 취소하면됩니다.
또한 기본적으로 asp.TextBox/Input은 Page_Load에서 비활성화됩니다.
//If checked it should enable the input.
//If unchecked it should disable the input.
If Port is Required?<label class="checkbox">
<input type="checkbox" id="isportreqinput" name="isportreqinput" runat="server" onclick="fncport(this.form.isportreqinput, this.form.porttxt);" />
<span class="metro-checkbox">Check Me</span>
</label>
//This is the input I need to disable/enable depending on the checkbox
<input type="text" name="porttxt" id="porttxt" runat="server" disabled="disabled" />
<script type="text/javascript">
function fncport(control, objname) {
if (control.checked == true) {
objname.disabled = false;
}
if (control.cheched == false) {
objname.disabled = true
}
}
</script>
흠 ... 이상한. 왜 그게 전부일까요? 'fncport (this.form.isportreqinput, ...)'는 디폴트 ASP.net이 다른 ID를 렌더링하기 때문에 컨트롤을 알지 못한다. –
죄송합니다, 무슨 말씀인지 모르시겠습니까? – jorame
브라우저에서 렌더링 된 HTML 코드를 보면 컨트롤의 ID가'ctl00_ContentPlaceHolder_isportreqinput'처럼 정말 아름답 지 않아야합니다. 그러나'onclick' 핸들러는 원래의 ID로 함수를 호출합니다. 기본 ID 렌더링을 변경하지 않았다면, 이것은 렌더링 된 클라이언트 ID를 얻기 위해'fncport (this.form. <% = isportreqinput.ClientID %>, ...)'이어야합니다. –