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