There is a textbox on my form with a linkbutton positioned next to it. The ID of the textbox is textbox1 and the linkbutton is lbSearch.
In the page_load event, I include the following code:
this.TextBox1.Attributes.Add("onkeydown", "if(event.which || event.keyCode)
{
if ((event.which == 13) || (event.keyCode == 13))
{
document.getElementById('" + this.lbSearch.ClientID + "').click();
return false;
}
}
else
{
return true
}; ");
This code works in Firefox but not in Internet Explorer due to how the linkbutton is rendered as an anchor tag.
The linkbutton is rendered like this:
<a href='javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$zoeken1$lbSearch", "", true, "search", "", false, true))' id="ctl00_zoeken1_lbSearch">zoek</a>
I attempted a solution with the following code snippet:
function onkeydown does not always return a value
rule: 1, column: 243
source:
if(event.which || event.keyCode)
{
if ((event.which == 13) || (event.keyCode == 13))
{
var link = document.getElementById('ctl00_zoeken1_lbSearch');
__doPostBack(link.id.replace('_','$'),'');
return false;
}
else
{
return true;
}
}
else
{
return true;
};
Is there a way to resolve this issue without converting the linkbutton into an imagebutton or regular button?