2014-04-07 66 views
0

我有一箇中繼器,其中有一個按鈕。然後在該按鈕的onclientclick上移除相應的div,然後使用ajax進行數據庫查詢。在jquery中刪除div

當我只是做div.remove()其工作正常。但是當我刪除代碼放置在阿賈克斯的成功部分..它不是頁面刷新其工作的罰款後working..but ..

我的代碼是...

<asp:UpdatePanel ID="UpdatePanel1" runat="server"> 
       <ContentTemplate> 
        <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1" > 
         <ItemTemplate> 
          <div class="grid_4" data-gen="afc" data-gen-offset="bottom-in-view" id='<%#Eval("Id") %>'> 
           <a class="services-block" href="#"> 
            <ul class="icon"> 
             <li class="fontawesome-icon large circle-two fa fa-laptop"></li> 
             <li class="fontawesome-icon large circle-deg-two fa fa-laptop"></li> 
            </ul> 
            <p> 
             <asp:Label ID="lblGameTitle" runat="server" Text='<%# Eval("GameName") %>'></asp:Label></p> 
            <div class="text"> 
             <asp:Label ID="lblOpponent" runat="server" Text='<%# Eval("OpponentOne") + " Vs. "+ Eval("OpponentTwo") %>'></asp:Label> 
             <br /> 
             <asp:Label ID="lblDateTime" runat="server" Text='<%# "Date : "+ Eval("GameDate") + "<br />Time : " + Eval("GameTime") %>'></asp:Label> 
             <br /> 

             <asp:RadioButton ID="rbtnBlue" runat="server" Text="High" GroupName="UrlColor" Checked="true" /> 
             <asp:RadioButton ID="rbtnRed" runat="server" Text="Low" GroupName="UrlColor" /> 


             <asp:Button ID="btnOpponentOne" runat="server" Text='<%# Eval("OpponentOne") %>' OnClientClick="opponentOne(this);"/> 
             <asp:Button ID="btnOpponentTwo" runat="server" Text='<%# Eval("OpponentTwo") %>' OnClientClick="opponentTwo(this);"/> 
             <asp:Button ID="btnDraw" runat="server" Text="Draw" OnClientClick="Draw(this);"/> 
             <br /> 
            </div> 
           </a> 
          </div> 
          <asp:HiddenField ID="gid" runat="server" Value='<%# Eval("ID") %>' /> 
          <asp:HiddenField ID="opOne" runat="server" Value='<%# Eval("OpponentOne") %>' /> 
          <asp:HiddenField ID="opTwo" runat="server" Value='<%# Eval("OpponentTwo") %>' /> 
         </ItemTemplate> 
        </asp:Repeater> 
        <%-- <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />--%> 

       </ContentTemplate> 
      </asp:UpdatePanel> 

和JS是...

function opponentOne(btn) { 
      var s = btn.id; 
      var start = s.indexOf("btnOpponentOne"); 
      var end = s.lastIndexOf("_"); 
      sub = s.substring(start, end); 
      s = s.replace(sub, "opOne"); 
      var hidden = document.getElementById(s); 
      var id = hidden.value; /* option */ 
      //alert(id); 
      var divId = aaaa1(btn); 
      //alert(divId); 
      var check = CheckRadio(btn); 
      //alert(check); 
      var tid = getParameterByName('tid'); 
      //alert(tid); 
      var inputText = id + "~" + divId + "~" + check+"~"+tid; /* option + div id(id) + high/low */ 
      /* database connection */ 
      if (confirm('Are your sure ?')) { 
       $.ajax({ 
        type: "POST", 
        url: "/play_match.aspx/AddPrediction", 
        data: '{\'InputText\':\'' + inputText + '\'}', 
        contentType: "application/json; charset=utf-8", 
        dataType: "json", 
        success: function (response) { 
         if (response.d == "Success") { 
          alert('done..............'+divId); 
          $('#' + divId).remove(); 
         } 
        }, 
        failure: function (response) { 
         alert('fail'); 
         alert(response.d); 
        }, 
        error: function (response) { 
         alert('error'); 
         alert(response.d);`enter code here` 
        } 
       }); 
      } 

     } 
+0

該警報是否立即生效或剛刷新頁面後立即生效? – Arman

回答

0

你將不得不明確刷新更新面板刷新用戶界面。嘗試使用__doPostBack(UpdatePanel1,'');更新它。祝你好運。