On [Enter] keyup of textbox incorrect validation group being fired
I have two validation groups on a form (we will call them VG1 & VG2). I have the following code:
<asp:TextBox ID="textbox1" runat="server" ValidationGroup="VG2" />
<asp:RequiredFieldValidator Text="*" ForeColor="#C301B9" ID="RequiredFieldValidator1" runat="server" ErrorMessage="My error message" ControlToValidate="textbox1" Validati开发者_如何学编程onGroup="VG2" />
When this control has focus and I hit enter the validation summary displays the validation error messages for VG1.
VG1 fields are not visible (set via JS). I think I may need to also disable VG1 validation group summary.
Any help with this would be appreciated.
Hitting enter when in the text box is probably submitting the form or doing the equivelent of clicking some button that is in the VG1 validation group. If you put everything in VG2 within a Panel
control and set the DefaultButton
property on the panel to be a button in VG2 then hitting enter in the text box will no longer fire the validators in VG1. If you are simply hiding controls vai javascript remember they are still there on the page and their actions can still be triggered.
精彩评论