'How can bind value in Web view in URL textbox in UWP
I am trying to auto bind value in page which is open by URL in UWp and I am using C#. This is part of my C# Code
public LayoutOnlineAccess()
{
this.InitializeComponent();
String sURL = "https://www.uptodate.com/login";
try
{
if (NetworkAvailabilty.Instance.IsNetworkAvailable)
{
Uri webURL = new Uri(sURL);
webView1.Navigate(webURL);
webView1.Settings.IsJavaScriptEnabled = true;
}
else
CommonCls.ShowToastMessage("Internet Connection is not available.");
}
catch (Exception){}
}
private async void ctlBrowser_NavigationCompleted(WebView sender, WebViewNavigationCompletedEventArgs args)
{
try
{
string functionUsernamee = string.Format("document.getElementById('userName').value = '123456789';");
string functionUsername = string.Format(@"alert('TEST')");
await webView1.InvokeScriptAsync("eval", new string[] { functionUsernamee });
webView1.Stop();
}
}
catch (Exception ex)
{
//new ExceptionHelper().AddException(ex.Message, this.ToString(), "ctlBrowser_NavigationCompleted");
}
}
I tried alert for check. ITs working or Not but not worked. This is XAML CODE
<WebView x:Name="webView1" Height="985" Width="1920" ScriptNotify="WebView1_ScriptNotify_1"
NavigationStarting="ctlBrowser_NavigationStarting" NavigationCompleted="ctlBrowser_NavigationCompleted" />
Thank You Best Regards
Solution 1:[1]
I have to say you can't direct bind a value from your c# code behind to the website using data binding. You still need to manually assign the value to the website using WebView.InvokeScriptAsync. When calling the InvokeScriptAsync, please make sure the JS method could run correctly.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Roy Li - MSFT |
