【问题标题】:Prevent Refresh on anchor tag Click防止在锚标记上刷新单击
【发布时间】:2017-12-24 13:34:33
【问题描述】:

我想使用这样的锚标记从任何内容页面加载页面。我想防止在锚标签 Click 上刷新页面,但同时它应该加载不同的页面。下面的例子是内容页面

<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>

【问题讨论】:

  • 使用LinkButton并通过点击加载内容页面
  • 什么都没发生@Imad

标签: asp.net url anchor c#-3.0


【解决方案1】:

以下不适用于服务器端控件,您还需要将所有内容页面更改为单独的。

$('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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-18
      • 1970-01-01
      • 1970-01-01
      • 2014-09-18
      相关资源
      最近更新 更多