Share via

Assigning entry input into a text string without hitting enter/return/checkmark

Bruce Krueger 331 Reputation points
2022-07-08T22:55:48.433+00:00

Is there a way to assign the entry input into a text string without the user hitting enter/return/checkmark?
I am having trouble with users not hitting the enter/return/checkmark before hitting the login button and therefore the loginemailaddress string is empty.
In this example Label3.Text is always null unless they hit the enter/return/checkmark on their keyboard after entering the email address.

 public partial class MainPage : ContentPage  
    {  
        string loginemailaddress;  
         
        public MainPage()  
        {  
            InitializeComponent();  
        }  
        public void Email_TextChanged(object sender, TextChangedEventArgs e)  
        {  
            loginemailaddress = e.NewTextValue;  
            loginemailaddress = loginemailaddress.ToLower();  
            Label1.Text = "1:" + loginemailaddress;  
        }  
        public void Email_Completed(object sender, EventArgs e)  
        {  
  
            loginemailaddress = ((Entry)sender).Text;  
            loginemailaddress = loginemailaddress.ToLower();  
            Label2.Text = "2:" + loginemailaddress;  
        }  
        
  
        private async void EnterButton_Clicked(object sender, EventArgs e)  
        {  
            Label3.Text = "3:" + loginemailaddress;  
  
        }  
          
    }  
Developer technologies | .NET | Xamarin

Answer accepted by question author

Anonymous
2022-07-12T08:58:35.687+00:00

Hello,​

When the text in the Entry changes, the Email_TextChanged method executes. Here is InputView.TextChanged Event
You can add TextChanged="Email_TextChanged" for your <Entry> like following code. Then you click the Button, you can get the text without hitting enter/return/checkmark,

   <Entry x:Name="Emailaddress"  
                       Placeholder="emailaddress"  
                       PlaceholderColor="DimGray"  
                       ClearButtonVisibility="WhileEditing"  
                       TextChanged="Email_TextChanged"  
                       Keyboard="Email"  
                       Completed="Email_Completed"  
                       />  

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.

Was this answer helpful?


0 additional answers

Sort by: Most helpful

Your answer

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