Reputation: 448
I have a form in my windows phone 7 app which contains a few textboxes and a radiobutton. I want to reset the value of the textboxes and radio button on clicking the reset button. I am able to clear the textboxes but donot Know how to clear the value of the radio button. Please help:
My form is:
<TextBox GotFocus="OnGotFocus" Canvas.Left="6" Canvas.Top="6" Height="74" Name="name" Text="*Name" Width="453" BorderThickness="0"/>
<TextBox GotFocus="OnGotFocus1" Canvas.Left="6" Canvas.Top="66" Height="74" Name="age" Text="*Age" Width="453" BorderThickness="0" />
<TextBlock Canvas.Left="20" Canvas.Top="157" Height="44" Name="gen" Text="Gender" Foreground="Black" FontFamily="Verdana" FontSize="24" Width="134" />
<RadioButton Canvas.Left="139" Canvas.Top="157" FontStyle="Italic" Foreground="Black" Content="Male" Height="71" Name="male" Width="154" />
<RadioButton Canvas.Left="139" Canvas.Top="207" FontStyle="Italic" Foreground="Black" Content="Female" Height="71" Name="fem" Width="140" />
<TextBox GotFocus="OnGotFocus2" Canvas.Left="6" Canvas.Top="267" Height="74" Name="sadd" Text="*Street Address" Width="453" BorderThickness="0"/>
<TextBox GotFocus="OnGotFocus3" Canvas.Left="6" Canvas.Top="327" Height="74" Name="cadd" Text="*City Address" Width="453" BorderThickness="0"/>
<TextBox GotFocus="OnGotFocus4" Canvas.Left="6" Canvas.Top="387" Height="74" Name="eadd" Text="*Email Address" Width="453" BorderThickness="0"/>
<TextBox GotFocus="OnGotFocus5" Canvas.Left="6" Canvas.Top="447" Height="74" Name="phn" Text="*Phone" Width="453" BorderThickness="0"/>
<TextBox GotFocus="OnGotFocus6" Canvas.Left="6" Canvas.Top="507" Height="74" Name="zip" Text="*Zip Code" Width="453" BorderThickness="0"/>
My code for resetting on clicking the reset button is:
private void reset_Click(object sender, RoutedEventArgs e)
{
name.Text = "";
age.Text = "";
sadd.Text = "";
cadd.Text = "";
eadd.Text = "";
phn.Text = "";
zip.Text = "";
}
Please add the code that i should add here to reset the radio button
Now on clicking submit button if i want to check that whether male or female has been selected or not, how can i do that. For text box i am doing the following code:
private void submit_Click(object sender, RoutedEventArgs e)
{
if (name.Text == "")
{
MessageBox.Show("Please Enter the name");
name.Focus();
}
}
Upvotes: 0
Views: 440
Reputation: 3331
There is a property named content which is equivalent to a textbox text property
And this is how you are gonna set it
male.IsChecked=false;
male.Content=String.Empty;
And regarding the edits.
assign a common groupname property to both the radiobuttons. ie
<RadioButton Canvas.Left="139" Canvas.Top="157" FontStyle="Italic" GroupName="Gender" Foreground="Black" Content="Male" Height="71" Name="male" Width="154" />
<RadioButton Canvas.Left="139" Canvas.Top="207" FontStyle="Italic" GroupName="Gender" Foreground="Black" Content="Female" Height="71" Name="fem" Width="140" />
This makes either of the two selected everytime in xaml.
Now getting the value of a radiobutton in code should be like.
if(male.IsChecked==true)
{
string gender=male.Content.ToString();
}
else if(female.isChecked==true)
{
string gender=female.Content.ToString();
}
else //none of them is selected.
{
MessageBox.Show("Text");
}
Upvotes: 1