2013-07-17 2 views
0
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" /> 
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script> 
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script> 

jQuery 자동 완성을 ajax 및 json 데이터와 함께 사용하고 있지만 선택한 결과를 요소에 추가하면 문제가 발생합니다. ex->http://jqueryui.com/autocomplete/#remote-jsonp ol, div, p 및 ul에 잘 추가 할 수 있지만 asp : ListBox에 추가하여 결과 서버 쪽을 쉽게 바인딩 할 수 있습니다.appending ListBox

아래 함수는 내 ListBox를 그냥 비 웁니다. 왜 새로운 요소를 추가하는 것이 효과가 없는지 확신 할 수 없습니다.

 function log(message) { 
      $("#<%= lbx_log.ClientID %>").text(+"<asp:ListItem Text=\""+message+"\" />").appendTo("#log"); 
     } 

HTML/ASP

<div > 
    <asp:ListBox runat="server" id="lbx_log" style="height: 200px; width: 300px; overflow: auto;" class="ui-widget-content"> 
    <asp:ListItem Text="blank" /> 
</asp:ListBox> 
</div> 
<asp:Button runat="server" ID="btn_back" Text="Back ←" OnClick="btn_back_Click" /> 
<asp:Button runat="server" ID="btn_save" Text="save" OnClick="btn_save_Click" /> 
<asp:Button runat="server" ID="btn_next" Text="Next →" OnClick="btn_next_Click" /> 
</div> 

</form> 
</body> 

+0

클라이언트에서 100 % 발생하기 때문에 서버 측 코드가 유용하지 않은 것은 질문에 대한 답변입니다. .NET 코드가 아닌 HTML을 표시하십시오. –

답변

0

$("#<%= lbx_log.ClientID %>").text(+"<asp:ListItem Text=\""+message+"\" />"));

이것은 HTML로 서버 측 컨트롤을 추가하려고 시도합니다. 그런 식으로 작동하지 않습니다. asp.net은 클라이언트에 페이지를 보내기 전에 모든 서버 컨트롤 (예 : <asp:anything)을 순수한 html로 변환합니다. 브라우저에서 페이지 소스를보고 렌더링 된 html로 작업해야합니다.

+0

좋아, 알았어. StuckOnSimpleThings

+0

그래서 옵션 값을 추가하면 저장 버튼을 클릭 할 때 포스트 백에서 호출 할 수있게됩니다. – StuckOnSimpleThings

+1

이 응답을 참조하십시오 : http://stackoverflow.com/questions/4849050/ 문제 발생 목록 상자 항목이 코드 뒤에 숨겨진 jquery –