asp.NET LinkButton not working in Google Chrome

一世执手 提交于 2019-12-20 05:52:39

问题


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>

回答1:


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);
}



回答2:


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.




回答3:


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




回答4:


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.



来源:https://stackoverflow.com/questions/1259489/asp-net-linkbutton-not-working-in-google-chrome

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!