2016-12-02 4 views
0

runat = "server"를 사용하여 버튼 클릭 이벤트에서 보이지 않거나 볼 수있는 입력 태그 type = "text" 다음은 runat = "server"를 사용하여 코드 숨김으로 html 입력 텍스트 컨트롤을 설정하는 방법

내가 아약스 다음은/눈에 보이는 보이지 않는하지만, 할 수 있어요 RUNAT = "서버"를 사용하는 경우

[WebMethod] 
    public static List<string> GetAutoCompleteData(string Col3) 
    { 
     List<string> result = new List<string>(); 
     if ((dtClone != null) && (dtClone.Rows.Count > 0)) 
     { 
      DataRow[] foundRows; 
      string expression = "Col3 LIKE '%" + Col3 + "%'"; 

      // Use the Select method to find all rows matching the filter. 
      foundRows = dtClone.Select(expression); 
      for (int i = 0; i < foundRows.Length; i++) 
       result.Add(foundRows[i][2].ToString()); 
     } 
     return result; 

    } 

뒤에

$(document).ready(function() { 
       SearchText(); 
      }); 
      function SearchText() 
      { 
       $(".autosuggest").autocomplete({ 
        source: function (request, response) { 
         $.ajax({ 
          type: "POST", 
          contentType: "application/json; charset=utf-8", 
          url: "CalenderDetails.aspx/GetAutoCompleteData", 
          data: "{'Col3':'" + document.getElementById('txtSearch').value + "'}", 
          dataType: "json", 
          success: function (data) { 
           response(data.d); 
          }, 
          error: function (result) { 
           alert("Error"); 
          } 
         }); 
        } 
       }); 
      } 
     </script> 







    <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" /> 
       <br /> 
     <input type="text" id="txtSearch" class="autosuggest" /> 
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" > 

        <ContentTemplate> 
         <asp:Label ID="Label3" runat="server" Text="Label"></asp:Label> &nbsp;&nbsp;&nbsp; 

         <br /> 
         <br /> 
         <asp:GridView ID="Gr 

idView1" runat="server" AllowPaging="True" PageSize="20" OnPageIndexChanging="GridView1_PageIndexChanging" OnRowDataBound="GridView1_RowDataBound"> 
         <HeaderStyle BackColor="#FFCC99" /> 

        </asp:GridView> 

       </ContentTemplate> 
       <Triggers> 
        <asp:AsyncPostBackTrigger ControlID="GridView1" EventName="PageIndexChanging" /> 
        <asp:AsyncPostBackTrigger ControlID="btnSubmit" EventName="Click" /> 
       </Triggers> 
      </asp:UpdatePanel> 

코드를 코딩 것입니다 전화가 검색 작업을 수행하지 않습니다

어떤 문제가이 문제를 해결할 수 있습니까?

+0

코드에서 jQuery 메서드를 호출 할 수 있습니다. –

+0

아무도 도와 줄 수 있습니까? –

답변

0

runat="server"이고 ajax call을 동일한 textbox으로 만드는 두 가지 작업을 수행하는 데 어려움이 있습니다.

ClientIDMode="Static"을 사용하면 입력란의 ID를 변경하지 않고도 아약스 전화를 발신 할 수 있습니다. 당신이 jQuery를 사용하여 다음과 같은 코드를 사용할 수

<asp:TextBox ID="txtSearch" ClientIDMode="Static" runat="server"></asp:TextBox> 
0

,

function clicked(){ 
 
    console.log("sf"+$("#grand").css("visibility")) 
 
    if($("#grand").css("visibility")=="visible"){ 
 
$("#grand").css("visibility","hidden"); 
 
    } 
 
    else{ 
 
$("#grand").css("visibility","visible"); 
 
    } 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<input type="text" value="hello" id="grand"> 
 
<input type="button" value="hide/show" onclick="clicked()">

첫째

+0

편집 된 원본 코드 –

0

, 당신은 정말 당신의 버튼에 RUNAT = "서버"를 추가 할 해달라고합니다.

당신이 서버 측에 웹 방법을 적용 할 수 있습니다 올바른지,

및 클라이언트 측에서

, 당신은 당신의 웹 메소드를 호출하는 AJAX를 적용 할 수 있습니다.

는 서버 측에서 HTML 컨트롤을 숨기고 달성하기 위해

당신은 웹 방법이를 추가하여 스크립트 관리자와 jQuery를 적용 시도 할 수 있습니다.

ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "clientScript", "$(':text').toggle()", true); 

조건없이 유형 = "텍스트"를 숨기거나 표시 할 경우에는 토글을 사용해도됩니다.

그렇지 않으면 당신은 당신의 필요 조건을 구현하고

$(':text').show() 

또는

$(':text').hide() 

보여주는 양식에 컨트롤을 숨기기 위해 호출 할 수 있습니다.

+0

편집 된 코드 모든 aspx 컨트롤을 사용했습니다. "txtSearch"는 HTML 컨트롤입니다. 코드 숨김에서 버튼 클릭 이벤트에 txtSearch 컨트롤 숨기기/표시하고 싶습니다. –