This is a migrated thread and some comments may be shown as answers.

Change Border of TextBox On Text Change or Focus

1 Answer 84 Views
Input
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 18 Feb 2011, 09:26 PM
I am wanting to validate based on a complex set of rules the entry into a textbox.  My preference would be to keep that validation on the server side in the code behind as the logic is written there already so I do not want to maintain it in javascript too for client side validation.  How can I call a validation method either on text change or focus via ajax with this control?

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 21 Feb 2011, 10:13 AM
Hello Jeff,

You can use the CustomValidator to achieve the scenario. There you can attach the OnServerValidate event and set the TextBox property CausesValidation to true. Your aspx should be like this.
aspx:
<asp:TextBox ID="TextBox1" runat="server" ValidationGroup="a" CausesValidation="true"
            AutoPostBack="true">
</asp:TextBox>
<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="ErrorMessage!!"
            OnServerValidate="ValidateNumber" ValidationGroup="a">
</asp:CustomValidator>

Thanks,
Shinu.
Tags
Input
Asked by
Jeff
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or