Forum Xamarin.Forms

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

How to handle errors in WebView

vivaanmathurvivaanmathur Member ✭✭
edited May 2019 in Xamarin.Forms

I'm developing an app for my client and have configured a WebView in my Xamarin.forms application. How do I handle errors (like Address Unreachable, no internet, etc..)

I have added try clause and catch exception. But it doesn't work and the default unreachable page comes on android and a blank page on iOS if there is no Internet

try{WebView.Source = "example.com";}
catch (Exception){var htmlSource = new HtmlWebViewSource();
htmlSource.Html = @"

An Error!!!!

Could not be loaded

";
WebView.Source = htmlSource;}
I expect "This page could not be loaded" but instead I see the original android error page: "net::ERR_ADDRESS_UNREACHABLE"

BTW - I had to put example.com cuz forum was not letting me put links... and An Error!!!! is in H1, but it loaded incorrectly (rendered on the forum itself?

Tagged:

Best Answers

Answers

  • vivaanmathurvivaanmathur Member ✭✭

    Oh thank you so much!!! This one is so much better than Stack Over Flow who dont answer questions forever

    THANKS A LOT!!!

  • PacodosoPacodoso FRUniversity ✭✭✭

    How to do the same thing in the ViewModel?

    I've tried to create a custom WebView with the 2 custom events Navigated/Navigating, like explained there.

    But I can't get WebNavigatedEventArgs in the ViewModel...

Sign In or Register to comment.