ASP.NET default button (LinkButton) does not work in Google Chrome when there are multiple default values

I have an ASP.NET Webforms page that has some default buttons. In all browsers except for Google Chrome, they work as expected, but the wrong default button is launched in Chrome.

I read some common causes of this problem, for example. invalid HTML (putting Panel inside TABLE elements), but it is not.

I saw one similar question about stackoverflow, but there was no accepted answer.

Is there any solution to this problem?

Update:

I read on MSDN that LinkButtons are not suitable for installation as default buttons.

"Only ImageButton buttons and controls are supported."

I think this is a problem.

+4
source share
2 answers

I read on MSDN that LinkButtons are not suitable for installation as default buttons.

"Only ImageButton buttons and controls are supported."

0
source

I have never experienced such behavior personally. The DefaultButton property has always worked for me in Chrome, but there is a way around it if you cannot smooth it. You can enter short JavaScript in the controls for which you want to launch buttons. The following is a non-jQuery method:

StringBuilder script = New StringBuilder(""); script.Append("if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {"); script.Append("document.getElementById('" + Me.btnToFire.ClientID); script.Append("').click();return false;}} else {return true};"); this.txtControlToAttach.Attributes.Add("onkeydown", script.ToString()); 

Here is a jQuery solution that can be used to assign multiples in one block (unverified, so configuration may need to be done).

 function fireButtonClick(ctrl, event) { if(event.which || event.keyCode){ if ((event.which == 13) || (event.keyCode == 13)) { ctrl.click(); return false; } } else { return true; } } $(document).ready(function() { $("#<%=this.ControlToAttach.ClientID%>").keypress(function(event) { fireButtonClick($("#<%=this.btnToFire.ClientID%>"), event); }); $("#<%=this.ControlToAttach2.ClientID%>").keypress(function(event) { fireButtonClick($("#<%=this.btnToFire2.ClientID%>"), event); }); // Just keep adding controls here }); 
0
source

Source: https://habr.com/ru/post/1381278/


All Articles