admin管理员组文章数量:1026289
I've created a web page with textbox control as below -
<asp:TextBox ID="txtNumber" runat="server" size="5" MaxLength="9" AutoPostBack="True"
OnTextChanged="txtNumber_TextChanged" CssClass="txtBoxPage" Style="margin-left: 3px;"></asp:TextBox>
I'm facing an issue when pressing enter key in textbox. On Enter key press postback is not occured. Can you please provide me help so that on Enter Key Press, page should get postback and textbox server-side will get fire.
I've debug the code and found that the WebForm_TextBoxKeyHandler returns false when the ENTER key is pressed. Below is the rendered code for reference -
<input type="text" onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;" onchange="javascript:setTimeout('__doPostBack(\'textbox1\',\'\')', 0)" ... />
Thanks in advance.
I've created a web page with textbox control as below -
<asp:TextBox ID="txtNumber" runat="server" size="5" MaxLength="9" AutoPostBack="True"
OnTextChanged="txtNumber_TextChanged" CssClass="txtBoxPage" Style="margin-left: 3px;"></asp:TextBox>
I'm facing an issue when pressing enter key in textbox. On Enter key press postback is not occured. Can you please provide me help so that on Enter Key Press, page should get postback and textbox server-side will get fire.
I've debug the code and found that the WebForm_TextBoxKeyHandler returns false when the ENTER key is pressed. Below is the rendered code for reference -
<input type="text" onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;" onchange="javascript:setTimeout('__doPostBack(\'textbox1\',\'\')', 0)" ... />
Thanks in advance.
Share Improve this question asked Oct 3, 2012 at 12:39 Sumit DeshpandeSumit Deshpande 2,1552 gold badges21 silver badges36 bronze badges1 Answer
Reset to default 3Try following workaround -
//Page_Load method
txtNumber.Attributes.Add("onkeyup", "OnKeyUp(event);");
//JavaScript code
function OnKeyUp(event) {
var key = (event.keyCode) ? event.keyCode : event.which;
if (key != null) {
key = parseInt(key, 10);
if (key == 13) {
document.body.setActive();
document.body.focus();
window.event.srcElement.focus();
}
}
}
Above code will fire the PostBack event as focus is being lost and regained from the textbox.
I've created a web page with textbox control as below -
<asp:TextBox ID="txtNumber" runat="server" size="5" MaxLength="9" AutoPostBack="True"
OnTextChanged="txtNumber_TextChanged" CssClass="txtBoxPage" Style="margin-left: 3px;"></asp:TextBox>
I'm facing an issue when pressing enter key in textbox. On Enter key press postback is not occured. Can you please provide me help so that on Enter Key Press, page should get postback and textbox server-side will get fire.
I've debug the code and found that the WebForm_TextBoxKeyHandler returns false when the ENTER key is pressed. Below is the rendered code for reference -
<input type="text" onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;" onchange="javascript:setTimeout('__doPostBack(\'textbox1\',\'\')', 0)" ... />
Thanks in advance.
I've created a web page with textbox control as below -
<asp:TextBox ID="txtNumber" runat="server" size="5" MaxLength="9" AutoPostBack="True"
OnTextChanged="txtNumber_TextChanged" CssClass="txtBoxPage" Style="margin-left: 3px;"></asp:TextBox>
I'm facing an issue when pressing enter key in textbox. On Enter key press postback is not occured. Can you please provide me help so that on Enter Key Press, page should get postback and textbox server-side will get fire.
I've debug the code and found that the WebForm_TextBoxKeyHandler returns false when the ENTER key is pressed. Below is the rendered code for reference -
<input type="text" onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;" onchange="javascript:setTimeout('__doPostBack(\'textbox1\',\'\')', 0)" ... />
Thanks in advance.
Share Improve this question asked Oct 3, 2012 at 12:39 Sumit DeshpandeSumit Deshpande 2,1552 gold badges21 silver badges36 bronze badges1 Answer
Reset to default 3Try following workaround -
//Page_Load method
txtNumber.Attributes.Add("onkeyup", "OnKeyUp(event);");
//JavaScript code
function OnKeyUp(event) {
var key = (event.keyCode) ? event.keyCode : event.which;
if (key != null) {
key = parseInt(key, 10);
if (key == 13) {
document.body.setActive();
document.body.focus();
window.event.srcElement.focus();
}
}
}
Above code will fire the PostBack event as focus is being lost and regained from the textbox.
本文标签: javascriptOn Enter Key Press on textbox serverside postback event not getting firedStack Overflow
版权声明:本文标题:javascript - On Enter Key Press on textbox server-side postback event not getting fired - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745634759a2160378.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论