Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

198
Views
Email Validation ASP.NET WebForms Border

I have textbox and two validation (RequiredFieldValidator & RegularExpressionValidator) as bellow

<asp:TextBox runat="server" ID="txtEmailFrom" CssClass="form-control"></asp:TextBox>
<asp:RequiredFieldValidator 
    ID="RequiredFieldValidator3" 
    runat="server" 
    ErrorMessage="Field Required" 
    ControlToValidate="txtEmailFrom" 
    Display="Dynamic"
    ForeColor="Red"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator 
    ID="regexEmailValid" 
    runat="server" 
    ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" 
    ControlToValidate="txtEmailFrom" 
    ForeColor="Red"
    Display="Dynamic"
    ErrorMessage="Invalid Email Format"></asp:RegularExpressionValidator>

But with error I need the border of field to highlight with red. And for that the code bellow is written:

function ValidatorUpdateDisplay(val) {
        if (typeof (val.display) == "string") {
            if (val.display == "None") {
                return;
            }
            if (val.display == "Dynamic") {
                val.style.display = val.isvalid ? "none" : "inline";
                return;
            }
        }
        val.style.visibility = val.isvalid ? "hidden" : "visible";
        if (val.isvalid) {
            document.getElementById(val.controltovalidate).style.border = '1px solid #333';
        }
        else {
            document.getElementById(val.controltovalidate).style.border = '1px solid red';
        }
    }

The function is working only with RequiredFieldValidatior. I need to work with both (RequiredFieldValidator & RegularExpressionValidator) validation.

Thank you in advance.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Maybe you can set a breakpoint in your javascript function?

I suspect it gets called twice. You are using two validators on your ControlToValidate, one of them is valid, the other invalid. The javascript gets executed once by every validator, it handles both the situation where a validator is not valid, and where one is valid.

So apparently in your case the RequiredFieldValidator 'wins' and gets executed last.

I don't think overriding the framework function ValidatorUpdateDisplay is the right choice here. Given you are using ASP.NET WebForms, maybe an option is to include the Ajax Control Toolkit. It has a ValidatorCallout extension. I assume you could use this extension also without the 'callout', but only the HighlightCssClass-option.

http://www.ajaxtoolkit.net/ValidatorCallout/ValidatorCallout.aspx

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!