How to know if there is an error in a validator C #

0

I have a form in Webforms where an Email is entered.

You have two validators that work correctly: RequiredFieldValidator, RegularExpressionValidator.

<asp:TextBox ID="txtEmail" runat="server" MaxLength="100" placeholder="Ingrese Email" CssClass="form-control"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvEmail" runat="server" ControlToValidate="txtEmail" Display="Dynamic" ErrorMessage="*Ingrese Email." ForeColor="Red"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="revEmail" runat="server" ControlToValidate="txtEmail" Display="Dynamic" ErrorMessage="*Formato Email inválido." ForeColor="Red" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
<br />
<asp:LinkButton ID="btnEnviar" runat="server" CssClass="btn btn-primary" OnClick="btnEnviar_Click">
    <span class="glyphicon glyphicon-send"></span>&nbsp;Enviar
</asp:LinkButton>

The problem is, that the aspx.cs code needs to know if there is an error or not. To continue with the execution.

protected void btnEnviar_Click(object sender, EventArgs e) {
    //Capturar Email
    string email = txtEmail.Text;
    //if si no hay error --> ir a funcion
    funcionEmail(string email);
}//btnEnviar_Click
    
asked by Luis Pizarro Ramírez 13.02.2018 в 16:22
source

0 answers