0
<input id="TextBox1" name="nam"    type="text" tabindex="1" /> 
    <asp:TextBox ID="datepickereffective"  runat="server" />
        <asp:RequiredFieldValidator ID="RequiredFieldValidatorForDateEffective" 
          runat="server"  ControlToValidate="datepickereffective"  
                    ErrorMessage="Required"></asp:RequiredFieldValidator>
       <asp:Button ID="Button1" runat="server" Text="Submit"  OnClick="btnsubmit_onclick"/>

I want to check for the null values in the html input above .

HAVE TRIED:

Javascript onblur:dovalidation()
<script>
    do validation 
</script>

ISSUE : I want to validate input text without using RUNAT=SERVER because i am using jquery autocomplete and for some reason if i use runat="server" it is not picking the data. Also, my SUBMIT button is server side event because i am saving data from the text box . I cant even write a javascript function for my button click .

WHAT I WANT: Is there any property which forces the user to definetely click the html input so that i can handle the validation in client side . Because the javascript logic with onblur only works when i click it and dont slect anything. Any pointers?

1 Answer 1

3

You can use CustomValidator in this case if you would like. Here's sample code:

<input id="Text1" type="text" />
<asp:CustomValidator ID="CustomValidator1" runat="server" 
ErrorMessage="Cannot be empty" ValidationGroup="Html" ClientValidationFunction="dohtmlvalidation" Display="Dynamic"></asp:CustomValidator>

<asp:Button ID="Button3" runat="server" Text="Button" ValidationGroup="Html"/>

//JS function
function dohtmlvalidation(sender, args) {
            if ($("#Text1").val() == "") {
                args.IsValid = false;
            }
        }

Demo: Check the Html Input Validation section at the bottom (ignore other test controls)

Sign up to request clarification or add additional context in comments.

3 Comments

Your solution above is working but i also have required field validators along with custom validators .They are not showing required text.
<asp:TextBox ID="datepickereffective" runat="server" /> <asp:RequiredFieldValidator ID="RequiredFieldValidatorForDateEffective" runat="server" ControlToValidate="datepickereffective" ErrorMessage="Required"></asp:RequiredFieldValidator>
Add ValidationGroup="Html" to your RequiredFieldValidator

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.