asp.NET LinkButton not working in Google Chrome

2020-05-03 10:05发布

I have a page with several linkbuttons, and all of them is not working in Google Chrome. They are working well in IE and Firefox. Chrome Inspector can find the linkbutton and it has a javascript-postback attached for a postback call. The button is placed inside several panels, but that should not be the problem, or?

<asp:Panel runat="server" ID="pnlLike">
  <div class="singleRecept_Toolbar_Item">
    <asp:LinkButton ID="lnkBtnVote" runat="server" OnClick="VoteRecept">I like </asp:LinkButton>
    <asp:Image ID="imgVote" ImageUrl="/images/LCHF/likeIcon.gif" runat="server" Visible="true" />
  </div>
</asp:Panel>

4条回答
家丑人穷心不美
2楼-- · 2020-05-03 10:37

Add the following code to OnPreInit method of base page.

protected override void OnPreInit(EventArgs e)
{
    if (Request.UserAgent != null && (Request.UserAgent.IndexOf("AppleWebKit") > 0))  // added for compatibility issues with chrome 
    {
        this.ClientTarget = "uplevel";
    }

    base.OnPreInit(e);
}
查看更多
等我变得足够好
3楼-- · 2020-05-03 10:39

Disabling the "Chrome Toolbox (by Google)" extension fixed the issue for me. If you don't have that extension still try disabling all your Chrome extensions.

When I had the issue, my first instinct was that it was incompatible Javascript provided by ASP but then I noticed the same exact issue on certain links here at Stackoverflow.

Also worth noting is that only the left click was broken - middle clicking links still opened them in a new tab.

查看更多
家丑人穷心不美
4楼-- · 2020-05-03 10:46

If this works in other browsers and not chrome, then you should file a bug here.

查看更多
Luminary・发光体
5楼-- · 2020-05-03 10:49

You could try to open the JavaScript console in Chrome (Ctrl+Shift+j) and see if any errors are reported when loading the page or when clicking the buttons.

I've experienced problems with LinkButtons caused by totally unrelated JavaScript errors.

查看更多
登录 后发表回答