2017-07-19 292 views
2

我想要使用錨點標記來加載頁面,就像這樣從任何內容頁面轉到。我想阻止頁面刷新錨點標記單擊但同時它應該加載不同的頁面。下面的例子這裏是內容頁防止刷新錨點標記點擊

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"> 
    <a href="WebForm2.aspx">go</a> 
</asp:Content> 

和母版頁

<asp:UpdatePanel ID="UpdatePanel1" runat="server"> 
     <ContentTemplate> 
      <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"> 
      </asp:ContentPlaceHolder> 
     </ContentTemplate> 
    </asp:UpdatePanel> 
+2

使用'LinkBut​​ton'並加載內容頁面並點擊它 – Imad

+1

什麼都沒有發生@Imad –

回答

2

下面將不會在服務器端控制工作,還需要更改所有內容頁到個人。

$('a').click(function (e) { 
     var page = $(this).attr('href'); 
     if (page!='#') { 
      window.history.pushState("string", "Title", page); 
      $("#divid").load(page, function() { 
       //write your stuff 
      }); 
     } 
     e.preventDefault(); 
     e.stopPropagation(); 
     return false; 
    }); 
2
<a class="link1" href="WebForm2.aspx">go</a> 


<script> 
$(function(){ 
    $("a.link1").click(function() 
    { 
     $.get("WebForm2.aspx"); 
     return false; // prevent default browser refresh on "#" link 
    }); 
}); 
</script>