I had before this code that worked very well, but now, it does not work anymore in Chrome and IE10. I don't know why
Javascript
function EnterEvent(e, ctrl) {
var keycode = (e.keyCode ? e.keyCode : e.which);
if (keycode == 13) {
$('[id$=btnSave]').click();
}
else {
return false;
}
}
HTML
<asp:TextBox ID="txtAdd" runat="server" onkeyup="EnterEvent(event, this)" />
<asp:LinkButton ID="btnSave" runat="server" OnClick="btnSave_Click"></asp:LinkButton>
Server side
protected void btnSave_Click(object sender, EventArgs e)
{
//Operations
}
I ve already replaced this $('[id$=btnAddItem]').click();
with $('#btnAddItem').click();
but nothing at all. The server side is never triggered.
I had my controls in a ajaxpanel but like this it worked before. I tested with F12 developer tools. I arrived to the click part but nothing
Any ideas? thanks!
Well, I found the solution. The only thing that I needed to do was to replace this line from my code
$('[id$=btnSave]').click();
for this:
__doPostBack(linkCtrl, '');
The signature of the function ended like this.
function EnterEvent(e, ctrl, linkCtrl) {
And finally I assigned this event in the OnLoad and postback == false
txtAdd.Attributes.Add("onkeyup", "EnterEvent(event, this, '" + this.btnSave.UniqueID + "')"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.