Menu

#120 Press enter in an input@type=text and UpdatePanel faulty

open
nobody
None
5
2007-04-17
2007-04-17
No

When you have code like:
<anthem:Panel ID="pnl_control" runat="server" AutoUpdateAfterCallBack="true" ...>
<asp:TextBox id="T" .../>
<asp:Button UseSubmitBehavior="true" ID="B" />
</anthem:Panel>

When putting the input-cursor in the TextBox, and pressing enter, the form-submit is used, not the anthem custom submit on the button.

I solved my problem with this hack (registring in the OnInit, within a !IsPostBack if statement):
ScriptManager.RegisterClientScriptBlock(
this, typeof (Page),
"submitByEnterFixForAnthem",
@"function submitByEnterFixForAnthem_onkeypress(event)
{
if(event.keyCode==13) //enter pressed
{
document.getElementById('" + B.UniqueID + @"').click();
event.returnValue=false; //prevent the default action (form.submit)
if(event.preventDefault) event.preventDefault();
}
}",true);
T.Attributes["onkeypress"] = "submitByEnterFixForAnthem_onkeypress(event);";

Discussion


Log in to post a comment.