2010-03-13 2 views
0

마스터 페이지가 페이지에 존재하는 자바 스크립트에서 RadioButtonList에 액세스 할 때 오류가 발생하고 난 thefollwing 수행하려고내가 마스터 페이지가하고 RadioButtonList1를 포함 asp.net 페이지가

<script type="text/javascript"> 


      var radioButtonList = document.getElementById('<%=RadioButtonList1.ClientID%>'); 
      if(radioButtonList[0].checked) 
       document.getElementById("_secondTR").style.display = "block"; 
      else if (radioButtonList[1].checked) 
       document.getElementById("_secondTR").style.display = "none"; 
     } 
</script> 

<table style="width: 100%"> 
    <tr id="Tr1"> 
     <td> 
      <asp:RadioButtonList ID="RadioButtonList1" runat="server" BackColor="#FFCC99" 
       RepeatDirection="Horizontal" Width="117px" onclick="ShowHide()"> 
       <asp:ListItem Value="1">Yes</asp:ListItem> 
       <asp:ListItem Value="0">No</asp:ListItem> 
      </asp:RadioButtonList> 
     </td> 
    </tr> 
    <tr id="_secondTR" runat="server" style="display: none"> 
     <td> 
      <asp:RadioButton ID="Five" runat="server" GroupName="1" BackColor="#669999" /> 
      <asp:RadioButton ID="Four" runat="server" GroupName="1" CausesValidation="True" BackColor="#669999" /> 
     </td> 
    </tr> 
</table> 

내가 할 수있는 자바 스크립트에서 RadioButtonList1을 얻지 못한다면 어떤 도움을받을 수 있습니까?

+0

.net에 관심이 없으므로 브라우저/인터프리터에 표시되는 실제 자바 스크립트 코드를 게시 할 수 있습니까? – HBP

답변

0

다음은

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 


<html xmlns="http://www.w3.org/1999/xhtml"> 
<head><title> 
    Untitled Page 
</title> 
</head> 
<body> 
    <form name="aspnetForm" method="post" action="Default.aspx" id="aspnetForm"> 
<div> 
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKLTY3MTM1NjkwNw9kFgJmD2QWAgIDD2QWAgIBD2QWAgIBD2QWAgIBDxYCHgVzdHlsZQUNZGlzcGxheTpub25lO2QYAQUeX19Db250cm9sc1JlcXVpcmVQb3N0QmFja0tleV9fFgQFLmN0bDAwJENvbnRlbnRQbGFjZUhvbGRlcjEkV2ViVXNlckNvbnRyb2wxJEZpdmUFLmN0bDAwJENvbnRlbnRQbGFjZUhvbGRlcjEkV2ViVXNlckNvbnRyb2wxJEZpdmUFLmN0bDAwJENvbnRlbnRQbGFjZUhvbGRlcjEkV2ViVXNlckNvbnRyb2wxJEZvdXIFLmN0bDAwJENvbnRlbnRQbGFjZUhvbGRlcjEkV2ViVXNlckNvbnRyb2wxJEZvdXLEUVfizbUknWTXdgpHXciIE+acfQ==" /> 
</div> 

<div> 

    <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWBgLV9tHzCQLJ7qOsBgLW7qOsBgLGgYnCCgKixI2BBALP88ewCU+8LBEmqBjXFfT7h0XYnYX89px3" /> 
</div> 
    <div> 
     asda sd sd as das 



<script type="text/javascript"> 
     function ShowHide() 
     { 
    var radioButtonList = document.getElementById('ctl00_ContentPlaceHolder1_WebUserControl1_RadioButtonList1'); 

      if(radioButtonList[0].checked) 
       document.getElementById("_secondTR").style.display = "block"; 
      else if (radioButtonList[1].checked) 
       document.getElementById("_secondTR").style.display = "none"; 
     } 
</script> 

<table style="width: 100%"> 
    <tr id="Tr1"> 
     <td> 
      <table id="ctl00_ContentPlaceHolder1_WebUserControl1_RadioButtonList1" onclick="ShowHide()" border="0" style="background-color:#FFCC99;width:117px;"> 
    <tr> 
     <td><input id="ctl00_ContentPlaceHolder1_WebUserControl1_RadioButtonList1_0" type="radio" name="ctl00$ContentPlaceHolder1$WebUserControl1$RadioButtonList1" value="1" /><label for="ctl00_ContentPlaceHolder1_WebUserControl1_RadioButtonList1_0">Yes</label></td><td><input id="ctl00_ContentPlaceHolder1_WebUserControl1_RadioButtonList1_1" type="radio" name="ctl00$ContentPlaceHolder1$WebUserControl1$RadioButtonList1" value="0" /><label for="ctl00_ContentPlaceHolder1_WebUserControl1_RadioButtonList1_1">No</label></td> 
    </tr> 
</table> 
     </td> 
    </tr> 
    <tr id="ctl00_ContentPlaceHolder1_WebUserControl1__secondTR" style="display:none;"> 
    <td> 
      <span style="background-color:#669999;"><input id="ctl00_ContentPlaceHolder1_WebUserControl1_Five" type="radio" name="ctl00$ContentPlaceHolder1$WebUserControl1$1" value="Five" /></span> 
      <span style="background-color:#669999;"><input id="ctl00_ContentPlaceHolder1_WebUserControl1_Four" type="radio" name="ctl00$ContentPlaceHolder1$WebUserControl1$1" value="Four" /></span> 
     </td> 
</tr> 

</table> 


    </div> 
    </form> 
</body> 
</html> 
0

.NET 버튼의 목록에 대한 테이블을 생성하는 브라우저에서 볼 수있는 실제 자바 스크립트 코드입니다, radioButtonList 그 테이블 referseto, 이 버튼을 얻기 위해 다음을 추가해야합니다 :

radioButtonList = radioButtonList.getElementsByTagName ('input'); 

즉각적인 문제는 해결되지만 getElementById ('_secondTR')는 오류가 발생합니다.

자바 스크립트를 다음과 같이 변경하면 원하는 것을 수행 한 것으로 보입니다.

function ShowHide() { 
    var radioButtonList = document.getElementById ('ctl00_ContentPlaceHolder1_WebUserControl1_RadioButtonList1'); 
    radioButtonList = radioButtonList.getElementsByTagName ('input'); 
    if (radioButtonList[0].checked) 
    document.getElementById ("ctl00_ContentPlaceHolder1_WebUserControl1__secondTR").style.display = "block"; 
    else if (radioButtonList[1].checked) 
    document.getElementById ("ctl00_ContentPlaceHolder1_WebUserControl1__secondTR").style.display = "none"; 
} 

.net 전문가에게이 스크립트를 생성하는 방법을 알려야합니다.

+0

마스터 페이지가 변경되면 오류가 발생하는 컨트롤에 statuc id를 사용합니다. –

관련 문제