Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3432454
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:27:04+00:00 2026-05-18T07:27:04+00:00

I have WebBrowser control on my winform. When I try navigate to some web-site

  • 0

I have WebBrowser control on my winform. When I try navigate to some web-site I get standard IE error pages like:

  • “Navigation to the webpage was canceled”
  • “The address is not valid”
  • “Page couldn’t be loaded”
  • etc.

I need to handle these errors and return custom error message to user. Is there any way to solve this issue?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T07:27:05+00:00Added an answer on May 18, 2026 at 7:27 am

    You want to handle the NavigateError event as shown here

    Edit: including example code from the link:

    using System;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    using System.Security.Permissions;
    
    namespace WebBrowserExtensibility
    {
        [PermissionSetAttribute(SecurityAction.Demand, Name="FullTrust")]
        public class Form1 : Form
        {
            [STAThread]
            public static void Main()
            {
                Application.Run(new Form1());
            }
    
            private WebBrowser2 wb = new WebBrowser2();
            public Form1()
            {
                wb.Dock = DockStyle.Fill;
                wb.NavigateError += new 
                    WebBrowserNavigateErrorEventHandler(wb_NavigateError);
                Controls.Add(wb);
    
                // Attempt to navigate to an invalid address.
                wb.Navigate("www.widgets.microsoft.com");
            }
    
            private void wb_NavigateError(
                object sender, WebBrowserNavigateErrorEventArgs e)
            {
                // Display an error message to the user.
                MessageBox.Show("Cannot navigate to " + e.Url);
            }
        }
    
        public class WebBrowser2 : WebBrowser
        {
            AxHost.ConnectionPointCookie cookie;
            WebBrowser2EventHelper helper;
    
            [PermissionSetAttribute(SecurityAction.LinkDemand, Name="FullTrust")]
            protected override void CreateSink()
            {
                base.CreateSink();
    
                // Create an instance of the client that will handle the event
                // and associate it with the underlying ActiveX control.
                helper = new WebBrowser2EventHelper(this);
                cookie = new AxHost.ConnectionPointCookie(
                    this.ActiveXInstance, helper, typeof(DWebBrowserEvents2));
            }
    
            [PermissionSetAttribute(SecurityAction.LinkDemand, Name="FullTrust")]
            protected override void DetachSink()
            {
                // Disconnect the client that handles the event
                // from the underlying ActiveX control.
                if (cookie != null)
                {
                    cookie.Disconnect();
                    cookie = null;
                }
                base.DetachSink();
            }
    
            public event WebBrowserNavigateErrorEventHandler NavigateError;
    
            // Raises the NavigateError event.
            protected virtual void OnNavigateError(
                WebBrowserNavigateErrorEventArgs e)
            {
                if (this.NavigateError != null)
                {
                    this.NavigateError(this, e);
                }
            }
    
            // Handles the NavigateError event from the underlying ActiveX 
            // control by raising the NavigateError event defined in this class.
            private class WebBrowser2EventHelper : 
                StandardOleMarshalObject, DWebBrowserEvents2
            {
                private WebBrowser2 parent;
    
                public WebBrowser2EventHelper(WebBrowser2 parent)
                {
                    this.parent = parent;
                }
    
                public void NavigateError(object pDisp, ref object url, 
                    ref object frame, ref object statusCode, ref bool cancel)
                {
                    // Raise the NavigateError event.
                    this.parent.OnNavigateError(
                        new WebBrowserNavigateErrorEventArgs(
                        (String)url, (String)frame, (Int32)statusCode, cancel));
                }
            }
        }
    
        // Represents the method that will handle the WebBrowser2.NavigateError event.
        public delegate void WebBrowserNavigateErrorEventHandler(object sender, 
            WebBrowserNavigateErrorEventArgs e);
    
        // Provides data for the WebBrowser2.NavigateError event.
        public class WebBrowserNavigateErrorEventArgs : EventArgs
        {
            private String urlValue;
            private String frameValue;
            private Int32 statusCodeValue;
            private Boolean cancelValue;
    
            public WebBrowserNavigateErrorEventArgs(
                String url, String frame, Int32 statusCode, Boolean cancel)
            {
                urlValue = url;
                frameValue = frame;
                statusCodeValue = statusCode;
                cancelValue = cancel;
            }
    
            public String Url
            {
                get { return urlValue; }
                set { urlValue = value; }
            }
    
            public String Frame
            {
                get { return frameValue; }
                set { frameValue = value; }
            }
    
            public Int32 StatusCode
            {
                get { return statusCodeValue; }
                set { statusCodeValue = value; }
            }
    
            public Boolean Cancel
            {
                get { return cancelValue; }
                set { cancelValue = value; }
            }
        }
    
        // Imports the NavigateError method from the OLE DWebBrowserEvents2 
        // interface. 
        [ComImport, Guid("34A715A0-6587-11D0-924A-0020AFC7AC4D"),
        InterfaceType(ComInterfaceType.InterfaceIsIDispatch),
        TypeLibType(TypeLibTypeFlags.FHidden)]
        public interface DWebBrowserEvents2
        {
            [DispId(271)]
            void NavigateError(
                [In, MarshalAs(UnmanagedType.IDispatch)] object pDisp,
                [In] ref object URL, [In] ref object frame, 
                [In] ref object statusCode, [In, Out] ref bool cancel);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an .Net Froms application that displays web pages through a WebBrowser control.
I have a C# WinForm app with a WebBrowser control on it. I'd like
I'm trying to automate in a WinForm using a WebBrowser control to navigate and
I have a winform with 2 WebBrowser control. Is there a way for one
I have a .NET Winforms web browser control that is rendering some application information,
I have a webbrowser control which I navigate to an URL that contains this
I have a webBrowser Control. HTML inside webBrowser control displays some small images (4kb
I have a WebBrowser control on a winform. The WebBrowser control shows an aspx
I have a winform and a WebBrowser control and I am changing an option
We have a windows application that contains an ActiveX WebBrowser control. As part of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.