0

i am using custom validator on one of my web form, the requirement is to check for the bookcode in the database and if it exists, then it should display message, now i am using custom validator for the same, what i want is, it should not postback if the custom validator returns false, instead it should act like normal validator and display message, i am using ServerSide Validation for the custom validator. here my code goes.

HTML Markup
<asp:TextBox ID="BookCode" runat="server" CssClass="textEntry"></asp:TextBox>


<asp:CustomValidator ID="BookCodeCustomValidator" runat="server" ControlToValidate="BookCode" CssClass="failureNotification fr"
                Display="Dynamic" ErrorMessage="Book already exists (Book Code should be unique)." OnServerValidate="ServerValidation"
                ToolTip="Book already exists (Book Code should be unique)." ValidationGroup="AddFacBookValidationGroup"></asp:CustomValidator>

and here is my code behind looks like

 protected void ServerValidation(object sender, ServerValidateEventArgs e)
    {
        objAddBooks.LibraryInfo = Transactions.LibraryFields.Bookcode;
        objAddBooks.Criteria = BookCode.Text;
        e.IsValid = (objAddBooks.BookExists) ? false : true;
    }
Abbas
  • 4,948
  • 31
  • 95
  • 161
  • 3
    So you want to avoid a postback but use a serverside validator? Do you see the contradiction yourself? The only thing i see, you could use jQuery $.ajax: http://brian.dobberteen.com/code/jquery_ajax_custom_validator/ – Tim Schmelter Dec 19 '12 at 23:19
  • Thanks thats cool, i would give it a try, also with the above code, my custom validator is not validating the field, it just skips the validation, i also tried removing ControlToValidate attribute – Abbas Dec 20 '12 at 00:07

0 Answers0