I'm in the process of debugging my web application and have hit a wall. I'm experiencing a behavior in Google Chrome only and my javascript ineptitude is keeping me from the solution.
I have an ASP page with an <asp:Panel>
control. Within the panel, I've setup a simple search textbox and am using an <asp:LinkButton>
to launch the search. The user enters their search text and should be able to hit enter (for usability sake) and the search results will display. This works in IE, but not in FireFox. There is a documented fix which I've applied to my page and have successfully gotten FireFox to function. Golden.
Except, the fix doesn't work in Google Chrome! A bit fishy, I fire up Firebug to debug the code... oh wait... it's a Chrome only issue. OK, fine I can handle debugging javascript without Firebug (sob) - I fire up the Chrome debugger and step through the code. It turns out that the javascript fix, previously mentioned, is being dropped by Chrome.
The fix script runs on page load and modifies the click handler of the LinkButton
:
var defaultButton = document.getElementById('<%= lnkSearch.ClientID %>');
if (defaultButton && typeof(defaultButton.click) == 'undefined') {
defaultButton.click = function() {
alert('function fired');
var result = true;
if (defaultButton.click) result = defaultButton.onclick();
if (typeof(result) == 'undefined' || result) {
eval(defaultButton.getAttribute('href'));
}
};
alert(typeof(defaultButton.click) != 'undefined');
}
And when running the page in the chrome debugger I step into function WebForm_FireDefaultButton()
and get to the line:
if (defaultButton && typeof(defaultButton.click) != "undefined") { ... }
and for some reason defaultButton.click
has bee "undefined"
. I'm stumped... What am I missing?
Also, I'm not using jQuery and it isn't a viable solution.
The HTML produced:
<div id="abc_pnlSearchPanel" language="javascript" onkeypress="javascript:return WebForm_FireDefaultButton(event, 'abc_lnkSearch')">
<div class="searchPanel">
<span class="searchText">
Type in stuff to search:
</span>
<span style="float: left;">
<input name="abc:txtSearch" type="text" id="abc_txtSearch" style="width:312px;" />
</span>
<a onclick="this.blur();" id="abc_lnkSearch" class="ButtonLayout" href="javascript:__doPostBack('abc$lnkSearch','')"><span>Search</span></a>
<div style="clear: both"></div>
</div>
</div>
I'm in the process of debugging my web application and have hit a wall. I'm experiencing a behavior in Google Chrome only and my javascript ineptitude is keeping me from the solution.
I have an ASP page with an <asp:Panel>
control. Within the panel, I've setup a simple search textbox and am using an <asp:LinkButton>
to launch the search. The user enters their search text and should be able to hit enter (for usability sake) and the search results will display. This works in IE, but not in FireFox. There is a documented fix which I've applied to my page and have successfully gotten FireFox to function. Golden.
Except, the fix doesn't work in Google Chrome! A bit fishy, I fire up Firebug to debug the code... oh wait... it's a Chrome only issue. OK, fine I can handle debugging javascript without Firebug (sob) - I fire up the Chrome debugger and step through the code. It turns out that the javascript fix, previously mentioned, is being dropped by Chrome.
The fix script runs on page load and modifies the click handler of the LinkButton
:
var defaultButton = document.getElementById('<%= lnkSearch.ClientID %>');
if (defaultButton && typeof(defaultButton.click) == 'undefined') {
defaultButton.click = function() {
alert('function fired');
var result = true;
if (defaultButton.click) result = defaultButton.onclick();
if (typeof(result) == 'undefined' || result) {
eval(defaultButton.getAttribute('href'));
}
};
alert(typeof(defaultButton.click) != 'undefined');
}
And when running the page in the chrome debugger I step into function WebForm_FireDefaultButton()
and get to the line:
if (defaultButton && typeof(defaultButton.click) != "undefined") { ... }
and for some reason defaultButton.click
has bee "undefined"
. I'm stumped... What am I missing?
Also, I'm not using jQuery and it isn't a viable solution.
The HTML produced:
<div id="abc_pnlSearchPanel" language="javascript" onkeypress="javascript:return WebForm_FireDefaultButton(event, 'abc_lnkSearch')">
<div class="searchPanel">
<span class="searchText">
Type in stuff to search:
</span>
<span style="float: left;">
<input name="abc:txtSearch" type="text" id="abc_txtSearch" style="width:312px;" />
</span>
<a onclick="this.blur();" id="abc_lnkSearch" class="ButtonLayout" href="javascript:__doPostBack('abc$lnkSearch','')"><span>Search</span></a>
<div style="clear: both"></div>
</div>
</div>
Share
Improve this question
edited Sep 19, 2020 at 9:52
Brian Tompsett - 汤莱恩
5,89372 gold badges61 silver badges133 bronze badges
asked Jun 29, 2009 at 20:30
Gavin MillerGavin Miller
43.9k22 gold badges127 silver badges191 bronze badges
2
- I'm not much of an ASP guy, can you post the HTML of what the panel produces? – Paolo Bergantino Commented Jul 10, 2009 at 22:25
- I'm having a similar problem, where in Chrome, I can get access to an HTMLAnchorElement (an <a> tag) but it doesn't have a click() function, even though it should. – Howard M. Lewis Ship Commented Oct 25, 2011 at 21:24
1 Answer
Reset to default 3I wasn't able to determine why this was happening in Chrome and none of the other browsers. But registering the script to execute on PageLoad solved the problem.
<body onLoad="DefaultButtonFix()">