Friday, October 14, 2011

Panel DefaultEnter property not working for ValidationSummary.

After a more detailed study of the problem revealed that the construction
<Asp: Panel ID = "Panel1" runat = "server" DefaultButton = "btnFind">  becomes 

<div id="ctl00_cphMain_Panel1" onkeypress="javascript:return WebForm_FireDefaultButton(event,'ctl00_cphMain_btnFind')"> 

But unfortunately, JavaScript onkeypress event of input field overridden by validator that controlling this field. So when you enter the wrong information and pressing the Enter button it's triggered validator, which displays the text of the error and stops processing events. 

So that would overcome this "evil" enough to use a different event. In this case, it will keydown.It will look like this:

panel
.Attributes.Add ( "onkeydown", "javascript: return WebForm_FireDefaultButton (event, '" + btnFind.ClientID + "')");

No comments:

Post a Comment