Clear Data field after submitting button

UnknownXam 21 Reputation points
2022-12-21T12:16:07.597+00:00

Hello Good Evening I have this problem and I cant solve this.
Anyway, information about my project in xamarin form;

  • Im using Vs 2019 version 16.11.13, latest one.
  • android only
  • .NET framework Version 4.8.04084

So, I have create account page, with fields and a button( register ). What I want is after clicking the register, the all fields will reset or clear the data entered by the user.
What I tried is in just text only like firstname, lastname, address and more, I successfully clear the data after clicking the button.

public void ClearData(){  
                textbox_firstname.Text = string.Empty;  
                textbox_lastname.Text = string.Empty;  
  
}  

but I have an entry fields of ;
-Datepicker; This is how my codes in datepicker..

//my design, the use of this control is to set an placeholder like "birth date"  
 <local:BirthdayDatePickerControl  
                                                        TextColor="Black"  
                                                      x:Name="entryField_DateOfBirth"  />  
  
I want to clear the data after clicking the register button. I didnt try any code on that datepicker because Idk how to do it.  
  

-Radiobutton; This is how my codes in radiobutton

/my design  
<StackLayout RadioButtonGroup.GroupName="IDtype" x:Name="ID_Type" >  
                                <RadioButton Content="National ID"/>  
                                <RadioButton Content="Voters ID"/>  
                                <RadioButton Content="Drivers License"/>  
                                <RadioButton Content="PRC ID"/>  
                                <RadioButton Content="Postal ID"/>  
  
                                <RadioButton Content="Others:"/>  
                              
                            </StackLayout>  
  
  
I trid some trial and error in clearing the data, this is what I did.  
  
  
 ID_Type.Children.Clear();  
  
but the output is error because my radiobutton value was removed .  

and an ImageResult which is basically an image element and my codes..

<Image   
                                    x:Name="Imgresult"   
                                    HeightRequest="150"   
                                    Aspect="AspectFill"/>  

but Idk also how to clear the imageresult.

My problem is how to clear data those fields. Thank you.

Developer technologies .NET Xamarin
0 comments No comments
{count} votes

Accepted answer
  1. Anonymous
    2022-12-22T05:12:00.057+00:00

    Hello,

    ========Update========
    Firstly, if you want to clear the text and save the previous date in the DataPicker,

    You need to pop up a new DatePickerDialog in the custom renderer and add a bindable property for nullable property.

    You can invoke clear text function in the ClearData method with myBirthdayDatePickerControl.Clear();

    Second, if you want to clear the check item for RadioButton, you need to traverse all of RadioButton and set the radioButton.IsChecked = false;

    End, if you want to clear the image, you can set source to null with Imgresult.Source = ImageSource.FromFile("");.

    Here is code about ClearData method.

       public void ClearData()  
               {  
                   textbox_firstname.Text = string.Empty;  
                   textbox_lastname.Text = string.Empty;  
                   myBirthdayDatePickerControl.Clear();  
                   var childs= ID_Type.Children;  
                   foreach (var child in childs) {  
                       RadioButton radioButton = child as RadioButton;  
                       radioButton.IsChecked = false;  
                   }  
                   Imgresult.Source = ImageSource.FromFile("");  
               }  
    

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.