Mohd Hadi

Mohd Hadi

  • NA
  • 7
  • 6.5k

text box with radiobutton how to validate

Jun 3 2012 9:32 AM
Dear Sir,

 I am using wpf with c# , i am new to programing ,ok

i have text box and two radio button , i want to redirect for anotherform after atleast one radiobutton is check please help me

  here is the design code

<StackPanel Grid.Row="0" Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">

            <Label Content="Invoice type:" Width="80" Height="30"></Label>
            <TextBox Name="txtInvoiceType" Width="25" Height="25"/>
            <Label Content="[1=Credit;2=Cash]" Width="110" Height="30"></Label>
        </StackPanel>

        <StackPanel  Grid.Row="1" Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
            <RadioButton Name="rbTyres" Content="Tyres" GroupName="Type" IsChecked="True"></RadioButton>
            <RadioButton Name="rbRawMaterial" Content="Raw Material" GroupName="Type" IsChecked="True"></RadioButton>
        </StackPanel>

        <StackPanel  Grid.Row="3" HorizontalAlignment="Center" Orientation="Horizontal" >
            <Button Name="btnOk" Content="Ok"  Height="40" Width="80" Click="btnOk_Click" />
            <Button Name="btnCancel" Content="Cancel"  Height="40" Width="80" />
        </StackPanel>


and here is the .cs code

 private void btnOk_Click(object sender, RoutedEventArgs e)
        {

            if (txtInvoiceType.Text == String.Empty)
            {

                MessageBox.Show("Fill textbox");

                return;

            }

            if (!(this.rbTyres.IsChecked || this.rbRawMaterial.IsChecked))
            {

                MessageBox.Show("Select atleast one radio");

                return;

            }
        }



Answers (8)