1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

radiobutton validation

Discussion in 'ASP.NET' started by Carlos, Jun 11, 2009.

  1. Carlos

    Carlos New Member

    Joined:
    Dec 5, 2008
    Messages:
    57
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    none
    Hi! can anyone tell me how can i apply validation that one of the radio button must be selected among three radio buttons.

    It is quite easy to handle it through radiobuttonlist but the format appear in list.

    Please provide code in C#.

    thanx
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,293
    Likes Received:
    365
    Trophy Points:
    83
    If you make one selected then there is no way user can go without making a selection.
     
  3. Carlos

    Carlos New Member

    Joined:
    Dec 5, 2008
    Messages:
    57
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    none
    Yes, but i want that none of them should be selected, and the validation enforce user to select any one by himself.
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,293
    Likes Received:
    365
    Trophy Points:
    83
    Check for the value of them and atleast should be one.
     
  5. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,343
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    Like :

    Code:
    bool flag = false;
    
    flag = flag || radiobutton1.Checked;
    flag = flag || radiobutton2.Checked;
    flag = flag || radiobutton3.Checked;
    
    if( flag )
    {
          // continue execution
    }
    else
    {
          // prompt user to select a radiobutton
    }
     
    Last edited: Jun 12, 2009

Share This Page