Cannot compile InputBox with await method

5 posts, 0 answers
  1. Domi
    Domi avatar
    2 posts
    Member since:
    Nov 2013

    Posted 06 Jan 2014 Link to this post

    Hi,

    I need to wait that a user enter some valuesin an RadInputPrompt using the following code :

    InputPromptClosedEventArgs args = await RadInputPrompt.ShowAwait(inputBoxTitle, MessageBoxButtons.OKCancel);

    however, I can't compile it and receive the following message :

    Error 1 The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task'. D:\DISK_C\Windows Phone\Telerik\Samples\Domi_InputPrompt_8\MainPage.xaml.cs 58 51 _CustomMessageBox

    Error 2 'Telerik.Windows.Controls.RadInputPrompt' does not contain a definition for 'ShowAwait' D:\DISK_C\Windows Phone\Telerik\Samples\Domi_InputPrompt_8\MainPage.xaml.cs 58 72 _CustomMessageBox

    I'm using VS  2012 and have included Telerik.Windows.Controls.Primitives & Telerik.Windows.Core for WP8 as said in the documentation.

    Any help will be very appreciated.

    Sincerly,

    Domi.



  2. Ivo
    Admin
    Ivo avatar
    90 posts

    Posted 08 Jan 2014 Link to this post

    Hello,
    What you need to do is just to add a "async" modifier in front of the method into which you are using "await".

    Regards,
    Ivo
    Telerik
    Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
  3. DevCraft banner
  4. Kay
    Kay avatar
    2 posts
    Member since:
    Sep 2013

    Posted 13 May 2014 Link to this post

    Ivo, not sure what you mean.

    I have the same problem with the code like this taken from the documentation http://www.telerik.com/help/windows-phone/radinputprompt-gettingstarted.html. Getting the same error above.

    ​private void Button_Tap(object sender, RoutedEventArgs e)
    {
    Style textBoxStyle = new System.Windows.Style(typeof(RadTextBox));
    textBoxStyle.Setters.Add(new Setter(RadTextBox.InputScopeProperty, "digits"));
    string messageTitle = "How much is the bill?";
    string message = "Please enter the amount of your meal";
    InputPromptClosedEventArgs args = ShowPrompt(textBoxStyle, messageTitle, message);
    amountEntered.Text = args.ToString();
    }

    private async Task<InputPromptClosedEventArgs> ShowPrompt(Style textBoxStyle, string messageTitle, string message)
    {
    return await RadInputPrompt.ShowAsync(messageTitle, MessageBoxButtons.OKCancel, message, InputMode.Text, textBoxStyle);
    }
  5. Todor
    Admin
    Todor avatar
    778 posts

    Posted 13 May 2014 Link to this post

    Hi Kay,

    You need to also add async modifier to the Button_Tap event handler:

    private async void Button_Tap(object sender, RoutedEventArgs e)
    {
        Style textBoxStyle = new System.Windows.Style(typeof(RadTextBox));
        textBoxStyle.Setters.Add(new Setter(RadTextBox.InputScopeProperty, "digits"));
        string messageTitle = "How much is the bill?";
        string message = "Please enter the amount of your meal";
        InputPromptClosedEventArgs args = await ShowPrompt(textBoxStyle, messageTitle, message);
        amountEntered.Text = args.ToString();
    }
     
    private async Task<InputPromptClosedEventArgs> ShowPrompt(Style textBoxStyle, string messageTitle, string message)
    {
        return await RadInputPrompt.ShowAsync(messageTitle, MessageBoxButtons.OKCancel, message, InputMode.Text, textBoxStyle);
    }

    Let me know if you need further assistance.

    Regards,
    Todor
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  6. Kay
    Kay avatar
    2 posts
    Member since:
    Sep 2013

    Posted 13 May 2014 in reply to Todor Link to this post

    Works, thank you!
Back to Top
DevCraft banner