0
    using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication3
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {


            if (IsPostBack)
                CustomValidator1.Validate();
        }

        protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
        {
            if (RadioButton1.Checked == false && RadioButton2.Checked == false)
                args.IsValid = false;
            else
                args.IsValid = true;

        }




    }
}

Here is the code I used to program my server side custom validator. I'm having trouble understanding how this works because if I take it out of the IsPostBack "if", it shows up in the summary when I start up the page but when I click a button it doesn't work. Anyone know what might be wrong?

Also as some side info, what is the major difference between server side and client side validation in terms of this type of validation ?

2
  • When you say "it doesn't work", what happens? Does it submit and not show you a validation message? Or does it not submit at all? Commented Nov 13, 2012 at 22:59
  • Also, when you say "when I click a button" are you still referring to the situation wher the IsPostBack "if" is removed? Commented Nov 13, 2012 at 23:00

1 Answer 1

1

The biggest difference betwen server side and client side validation (besides the obvious) is that client-side validation can prevent you from even submitting a page. Server-side validation only happens once the page has been submitted.

Mixing them can produce the situation where you, the user, have filled in all your fields, made everything the right length and value, and hit submit - and then when the page returns, there are more validation messages!

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

3 Comments

Thanks but could you propose a solution to my main problem ?
@AndrewB I would be happy to, but it would help if you could answer my questions in the comments.
I know what was wrong and I fixed most of it, basically I have a javascript ready and it works however I would like to know how I can send info about the radio buttons to the javascript function

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.