Reputation: 111
I used asp required field in my code but data in text box are sending even they are empty when clicking on the button and after they are sending, message of required field appears!! Please help! Thanks in advance...
The source code looks like this
<asp:Label ID="LabelUserName" runat="server" AssociatedControlID="UserName" meta:resourcekey="UserName">Nom :</asp:Label>
<asp:TextBox ID="UserName" runat="server" ValidationGroup="val" ></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Entrez your name " ControlToValidate="UserName" ForeColor="Red" ValidationGroup="val">
</asp:RequiredFieldValidator>
Here is the code of the button :
<asp:Button runat="server" Text="Envoyer" ID="Button1" Width="78px" ValidationGroup="val" />
Upvotes: 1
Views: 631
Reputation: 1
I think the required
will help you to solve this issue of field validator
eg:
<asp:TextBox ID="UserName" runat="server" required="required"></asp:TextBox>
Upvotes: 0
Reputation: 13955
Can't say for sure without seeing the code inside the event handle for your button click, but my guess is you are missing a check to be sure the page is valid. For example:
If (Page.IsValid) Then
' do your thing
Else
'do nothing
End If
Upvotes: 2