2011-08-10 7 views
4

3 개의 ASP.NET 텍스트 상자와 하나의 HiddenField가 있습니다. 세 번째 텍스트 상자의 값 (비활성화 됨)은 다른 두 값의 값에 따라 다릅니다.비활성화 된 ASP.NET 텍스트 상자 값 검색

수식 txtPricePad의 초기 값이 0이라고 가정

txtPricepad = txtPrice/txtCarton

<asp:TextBox ID="txtPriceCase" runat="server" onblur="javascript:GetPricePerPad();></asp:TextBox> 
<asp:TextBox ID="txtCarton" runat="server"></asp:TextBox> 
<asp:TextBox ID="txtPricePad" Enabled="false" runat="server" ></asp:TextBox> 
<asp:HiddenField ID="hdPricepad" runat="server"/> 

    function GetPricePerPad() 
    { 
    var priceCase = document.getElementById('ctl00_content_txtPriceCase').value; 
    var cartons  = document.getElementById('ctl00_content_txtCarton').value; 
    var res   = Number(priceCase)/Number(cartons); 

    document.getElementById('ctl00_content_txtPricePad').value = res; 
    document.getElementById('ctl00_content_hdPricepad').value = res; 
    } 

이고 txtPrice의 값이 변화 될 때 txtCarton 12. 이고 1200이면 GetPricePerPad()가 호출되므로 txtPricePad는 100이됩니다.

자바 스크립트가 성공적으로 변경되었습니다. txtPricePad의 값을 100으로 지정하지만 codebehind에서 txtPricePad를 호출 할 때 해당 값은 여전히 ​​0입니다. 그 이유는이 수식의 결과를 HiddenField에 할당 한 이유입니다. 이것을 할 수있는 다른 방법이 있습니까? 나는 HiddenField를 다시 사용하고 싶지 않다.

+0

[다음 jsp에서 사용할 수없는 텍스트 상자의 값을 가져오고 싶지만 null 값을 얻고 싶습니다.] (http://stackoverflow.com/questions/3757806/i-want-to- get-the-value-of-disabled-text-box-in-our-next-jsp-but-i-am-getting-nu) –

답변

10

Liz, 사용 안함을 True로 설정하는 대신 읽기 전용으로 (ReadOnly = True) 텍스트 필드를 만들 수 있습니까? 이유는 텍스트 필드가 비활성화되었을 때 POST 요청의 양식과 함께 제출되지 않기 때문입니다. See this question.

비활성화 된 것처럼 보이게하려면 버튼에 CssClass를 적용 할 수 있습니다.

+0

나는 이것이 훌륭한 제안이라고 생각한다. – Liz

+2

나는 1 년 전 이었지만, 무능력한 텍스트 박스의 가치를 되 찾으려고 노력하면서 8 시간의 하루를 낭비했다. –

2

나는 2 개 옵션

  1. 제출 양식에 txtPricePad 필드를 사용하려면 자바 스크립트 다른 입력 또는
  2. 사용에서 다시 계산 서버 측을 수행 중 하나가,

    아래 참조 사용할 것

    var pricePad = document.getElementById (< % = txtPricePad.ClientID %>);

    pricePad.disabled = false;

관련 문제