2012-11-15 89 views
0

我有一個listview.I想要防止一次又一次地加載頁面點擊編輯,更新和刪除。當我點擊編輯來編輯一個頁面時,頁面會執行回傳。所以我需要做的是爲了不執行回傳。你的函數之前如何防止在列表視圖中點擊按鈕回發

My code is 


    <script type="text/javascript"> 
    $(document).ready(function() { 
    $.ajax({ 
    type: "POST", 
    contentType: "application/json; charset=utf-8", 
    url: "TestOrigin.aspx/BindDatatable", 
    data: "{}", 
    dataType: "json" 

    }); 
    }); 
    </script> 
    <script type="text/javascript"> 

    function javascriptfunction() 
    { 
    return false; 
    } 
    </script> 


<asp:ListView ID="lstOrigin" 
         runat="server" 

    ItemPlaceholderID="PlaceHolder1" OnItemEditing="EditListViewItem" 
     OnItemCanceling="CancelListViewItem" 
     OnItemUpdating="UpdateListViewItem" 
     OnItemInserting="InsertListViewItem" 
     InsertItemPosition="LastItem" OnItemDeleting="DeleteListViewItem" 
DataKeyNames="ID" > 

     <LayoutTemplate> 
      <table width="100%" cellpadding="4" cellspacing="0"> 
       <tr class="header"> 
        <th > 
         <asp:LinkButton ID="lnkID" runat="server" CommandName="Sort" 
CommandArgument="ID" Text="ID" /> 
        </th> 
        <th > 
         <asp:LinkButton ID="lnkaddress" runat="server" 
CommandName="Sort" CommandArgument="Address" Text="Address" /> 
        </th> 
        <th > 
         <asp:LinkButton ID="lnkpin" runat="server" CommandName="Sort" 


CommandArgument="Pin" Text="Pin" /> 
        </th> 
        <th > 
         <asp:LinkButton ID="lnkcity" runat="server" CommandName="Sort" 
CommandArgument="City" Text="City" /> 
        </th> 
        <th> 
        <asp:LinkButton ID="lnkstate" runat="server" CommandName="Sort" 
CommandArgument="State" Text="State" /> 
        </th> 
        <th> 
        <asp:LinkButton ID="lnkcountry" runat="server" CommandName="Sort" 

CommandArgument="Country" Text="Country" /> 
        </th> 
        <th> 
        <asp:LinkButton ID="lnkport" runat="server" CommandName="Sort" 
CommandArgument="Port" Text="Port" /> 
        </th> 
        <th> 
        <asp:LinkButton ID="lnkoutsource" runat="server" CommandName="Sort" 

CommandArgument="Outsourcing" Text="Outsourcing" /> 
        </th> 
        <th> 
         Modify 
        </th> 
       </tr> 
       <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder> 
      </table> 
     </LayoutTemplate> 
     <ItemTemplate> 
      <tr class="item"> 
      <td> 
      <%# Eval("ID") %> 
      </td> 
       <td> 
        <%# Eval("Address") %> 
       </td> 
       <td> 
        <%# Eval("Pin") %> 
       </td> 
       <td> 
        <%# Eval("City") %> 
       </td> 
       <td> 
        <%# Eval("State") %> 
       </td> 
       <td> 
        <%# Eval("Country") %> 
       </td> 
       <td> 
        <%# Eval("Port") %> 
       </td> 
       <td> 
        <%# Eval("Outsourcing") %> 
       </td> 
       <td> 
        <asp:Button ID="lnkEdit" runat="server" Text="Edit"  
PostBackUrl="~/TestOrigin.aspx" CommandName="Edit" OnClientClick="javascriptfunction"/> 

         <asp:Button ID="lnkDelete" runat="server" Text="Delete" 
CommandName="Delete" ForeColor="Brown" OnClientClick="javascriptfunction"/> 
        </span> 
       </td> 
      </tr> 
     </ItemTemplate> 
     <AlternatingItemTemplate> 
      <tr> 
      <td> 
      <%# Eval("ID") %> 
      </td> 
       <td> 
        <%# Eval("Address") %> 
       </td> 
       <td> 
        <%# Eval("Pin") %> 
       </td> 
       <td> 
        <%# Eval("City") %> 
       </td> 
       <td> 
        <%# Eval("State") %> 
       </td> 
       <td> 
        <%# Eval("Country") %> 
       </td> 
       <td> 
        <%# Eval("Port") %> 
       </td> 
       <td> 
        <%# Eval("Outsourcing") %> 
       </td> 
       <td> 
        <asp:Button ID="lnkEdit" runat="server" Text="Edit" 
CommandName="Edit" OnClientClick="javascriptfunction" /> 

         <asp:Button ID="lnkDelete" runat="server" Text="Delete" 
CommandName="Delete" ForeColor="Brown" OnClientClick="javascriptfunction"/> 
        </span> 
       </td> 
      </tr> 
     </AlternatingItemTemplate> 
     <EditItemTemplate> 
      <tr class="edititem"> 

      <td> 

        <asp:TextBox ID="txtID" runat="server" Text='<%# Eval("ID") %>' /> 
       </td> 
       <td> 

        <asp:TextBox ID="txtAddress" runat="server" Text='<%# 
Eval("Address") %>' /> 
       </td> 
       <td> 

        <asp:TextBox ID="txtPin" runat="server" Text='<%# Eval("Pin") %>' 
/> 
       </td> 
       <td> 
        <asp:TextBox ID="txtCity" runat="server" Text='<%# Eval("City") %>' 
/> 
       </td> 
       <td> 
        <asp:TextBox ID="txtState" runat="server" Text='<%# Eval("State") 
%>' /> 
       </td> 
       <td> 
        <asp:TextBox ID="txtCountry" runat="server" Text='<%# 
Eval("Country") %>' /> 
       </td> 
       <td> 
        <asp:TextBox ID="txtPort" runat="server" Text='<%# Eval("Port") %>' 
/> 
       </td> 
       <td> 
        <asp:TextBox ID="txtOutsource" runat="server" Text='<%# 
Eval("Outsourcing") %>' /> 
       </td> 
       <td> 

         <asp:Button ID="btnUpdate" runat="server" Text="Update" 
CommandName="Update" OnClientClick=" javascriptfunction" /> 

        <asp:Button ID="btnCancel" runat="server" Text="Cancel" 
CommandName="Cancel" OnClientClick=" javascriptfunction" /> 
       </td> 
      </tr> 
     </EditItemTemplate> 

     </EmptyDataTemplate> 
    </asp:ListView> 

回答

1

投放回報

OnClientClick="return javascriptfunction()" 

,並在Java腳本函數在末尾寫

return false; 
+0

當我加入的OnClientClick =「javascriptfunction();返回false; 「那麼不會發生回發,也不會執行編輯,刪除和更新。如何解決這個問題。 – user1799611

+0

我想你做沒有後回,那麼你必須使用jQuery Ajax的 –

+0

我曾經使用過jquery ajax並更新了我的代碼。請告訴我爲什麼發回帖子 – user1799611

相關問題