i have 3 text box which must be in numeric, but i just want shown only one error message once either one of the text box was incorrect formating.
how can i archieve that?

I would use a ValidationSummary control to display the error message in one place. Then you configure the individual validation controls to suppress their error messages.

I know this method, but it still displaying others error message as well.
But is that other tricks?

I have a suggestion here...

Instead of doing like this, why cant to add a javascript that allows only numbers to be added in the control?

Because it saves the validation time and provides more simplicity...

How to do that? please show me a simplest example tq

The asp.net validation controls produce the javascript for client side validation. In addition, if you use the validation controls, the input will be checked server side as well, just in case the browser did not support javascript or is javascript was disabled/bypassed.

So if you do this with just regular javascript, you should also still validate server side.

Thanks, but it don't seem work for me.
i just want display 1 error message for 3 invalid text box input entered.

Try this:

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Validate Multiple Textbox</title>

    <script type = "text/javascript">
     function isNumeric(keyCode) {
         var r = ((keyCode >= 48 && keyCode <= 57) || keyCode == 8 ||
            (keyCode >= 96 && keyCode <= 105))
         if (!r) {
         document.getElementById('lblMsg').innerHTML = 'Only Number Allowed in the Textboxes!';
//             alert("please enter number");
         document.getElementById('lblMsg').innerHTML = '';
         return r;

    <form id="form1" runat="server">
        <asp:TextBox ID="TextBox1" onkeydown = "return isNumeric(event.keyCode);" onpaste = "return false;" runat="server"></asp:TextBox>
        <br />
        <br />
        <asp:TextBox ID="TextBox2" onkeydown = "return isNumeric(event.keyCode);" onpaste = "return false;" runat="server"></asp:TextBox>
        <br />
        <br />
        <asp:TextBox ID="TextBox3" onkeydown = "return isNumeric(event.keyCode);" onpaste = "return false;" runat="server"></asp:TextBox><br />
        <br />
        <asp:Label ID="lblMsg" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label></div>

Here you go, using asp.net validation controls and summary. The validation error is only shown in the summary and not next to the controls.

I tried to give you some hints, but see if this code helps you.

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="TextBox 1 only allows numeric values" ControlToValidate="TextBox1" ValidationExpression="[0-9]+" Display="None"></asp:RegularExpressionValidator><br />

<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ErrorMessage="TextBox 2 only allows numeric values" ControlToValidate="TextBox2" ValidationExpression="[0-9]+" Display="None"></asp:RegularExpressionValidator><br />

<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" ErrorMessage="TextBox 3 only allows numeric values" ControlToValidate="TextBox3" ValidationExpression="[0-9]+" Display="None"></asp:RegularExpressionValidator><br />

<asp:Button ID="Button1" runat="server" Text="Submit" />
<asp:ValidationSummary ID="ValidationSummary1" runat="server" />


is that possible to display beside the text box just need 1 message
For instance, 3 text boxes is empty input, so i only display 1 error message *

possible to doing this?


Thanks for the code, but it still not working.

For instance, 3 text boxes is empty input, so i only display 1 error message

Not with the validation controls. The sample that geniusvishal (+1 for him on a good job) provided does work, i just tested it.

If you go with a javascript solution, you should still validate server side for the reason i provided above.

but i can't work with geniusvishal solution? Maybe is child-page problem?

Javascript is client side so it does not have to do with master/child pages. Your issue is probably related to the element's ID. Remember I mentioned that in another one of your threads. Use the ClientIDMode property.

i am using ClientIDMode="Static" still cannot work with that onKeyDown property. But the onPaste is working. :/

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.