Validate empty fields C # [closed]

0

I have a project in ASP.NET where I validate the empty fields that are my textbox, what I want to do is not register the user without completing the fields and that when missing data to fill an asterisk and a message of missing data, but when filling in this missing information the asterisk and the message disappear. How can I do that?

    
asked by KlonDTS 23.02.2017 в 18:38
source

2 answers

3

You can use a RequiredFieldValidator control, for example, to make this your textbox:

<asp:TextBox ID="miTextBox" runat="server" CssClass="texto" Text="" Width="85%" Enabled ="true"></asp:TextBox>

And this your validator:

<asp:RequiredFieldValidator id="miValidador" runat="server"
                                        ControlToValidate="miTextBox"
                                        ErrorMessage="Campo Obligatorio"
                                        ForeColor="Red" Display="Dynamic" ToolTip="El campo es obligatorio" ValidationGroup="miGrupoValidacion">*</asp:RequiredFieldValidator>

And then on the register button, add this property:

CausesValidation="True"
    
answered by 23.02.2017 / 18:47
source
0

One of them and that I recommend is for HTML5, placing the attribute "requered" to the text fields that you consider must be mandatory to be filled by the user. There is a lot of information about it in the network.

Username: <input type="text" name="usrname" required>

Another way is JavaScript and there is also a lot of information about that.

The advantage that this solution can have is that the validation is done on the client.

    
answered by 23.02.2017 в 18:46