omnia Mm omnia Mm - 4 months ago 36
ASP.NET (C#) Question

how to validate two controls using one validator

i have two text boxes which the user should enter one of them
i wanna to use a validator which act exactly like Required Validator ,
as when the user press Submit the red alert written by the controls
any ideas

Thanks in advance


there is no built-in Validator that can do that, you will have to build a custom one:

try this:

or you could try using the code behind and use onclick event to validate the textboxes and then return an error inside a span, like this:

    protected void Button1_Click(object sender, EventArgs e)
    if (TextBox1.Text == null) 
        if (TextBox2.Text == null) 
            errorMsg.InnerText = "Error" //use a span with runat server