error trapping for WebView Xamarian

2 posts, 0 answers
  1. James
    James avatar
    1 posts
    Member since:
    Nov 2017

    Posted 09 Nov Link to this post

    Hi, How can I error trapping on WebView. I want to redirect to another page if url not found

          <Button
            android:id="@+id/Button4"
            android:layout_width="380.5dp"
            android:layout_height="1.0dp"
            android:background="#fa3e3e"
            android:textSize="11dp"
            android:layout_marginRight="295.5dp"
            android:visibility="invisible"
            android:text="Load" />
        <AbsoluteLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <WebView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/webView" />
        </AbsoluteLayout>

    click event on button4 will load the page:

        protected override void OnCreate(Bundle bundle)
            {
                
                base.OnCreate(bundle);
                SetContentView(Resource.Layout.Main);

                mWebClient = new WebClient();
                mWebView = FindViewById<WebView>(Resource.Id.webView);
                mButton4 = FindViewById<Button>(Resource.Id.button4);
                mButton4.Click += mButton4_Click;

     void mButton4_Click(object sender, EventArgs e)
            {
            mWebClient.ShouldOverrideUrlLoading(mWebView,"http://something.com");
            }
    }
       public class WebClient : WebViewClient
        {
            public override bool ShouldOverrideUrlLoading(WebView view, string url)
            {
                view.LoadUrl(url);  
                return true;
            }
           
        }

    Any help?  Thank you
  2. Lance | Tech Support Engineer, Sr.
    Admin
    Lance | Tech Support Engineer, Sr. avatar
    488 posts

    Posted 09 Nov Link to this post

    Hi James,

    This question is unrelated to Telerik UI for Xamarin, thus it is out-of-scope of the UI for Xamarin forums. I recommend asking your question on StackOverflow or in the Xamarin forums instead.

    Regards,
    Lance | Tech Support Engineer, Sr.
    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top