WPF WebBrowser with Bootstrap form - c#

I am working on a project that involves using a WPF WebBrowser to load a form created using Bootstrap JS framework. However, it appears that parts of the form (specifically drop-down select options buttons) do not function within the WebBrowser, despite working normally in IE11. The form does not retain drop-down selected values (on submit, the default value is recorded) and on change commands (e.g. loading specified data) do not work. I have searched extensively but have not found a solution that works. Drop down menus on non-Bootstrap forms seem to work when loaded, but Bootstrap forms on any site I load in the WebBrowser seem to fail.
Steps I have taken already that have not resolved the issue:
I have changed the FEATURE_BROWSER_EMULATION registry keys (among other keys suggested online) to change the default IE of the WebBrowser to IE11, and I have tested to make sure this is working, but it does not resolve the issue.
I have checked drop down boxes on other websites within the WebBrowser, which seem to be working fine.
I have ensured JavaScript is functional within the WebBrowser interface.
I have checked that the website works in IE11 outside of the WebBrowser interface.
I have tried the WebBrowser in both a Window and within a Form
I appreciate any help!

Related

WPF WebView2 - not able to disable Context Menu

Environment: Windows 10 Pro - ver. 1903, VS2019 latest version, WPF Core
When I have a manual control on an HTML page displayed inside WebView2 control, I can disable the context menu by simply adding oncontextmunu={return false;} as an attribute to <body> tag. But in most cases the web page is displayed based on user interaction (what page user navigates to etc.).
Question: How can we disable to context menu of a webpage displayed in WebView2 control?
Remarks:
I have noticed that in some cases where a JavaScript is loaded along with a webpage, the oncontextmunu={return false;} does not disable the context menu even if I add this attribute programmatically to the body tag of loaded page. I see AreDefaultContextMenusEnabled property of Microsoft.Web.WebView2.Core.CoreWebView2Settings class but VS2019 does not recognize any such property for WebView2.
There was a similar issue on the old WebBrowser control of WPF as described here and here, and I have the similar situation for WebView2.
According to bullet 5 of this Microsoft link the issue was resolved. But the solution there seems to be related to C++ while I'm using C#. Maybe, there is an alternative.
Mostly, the reason for disabling the Context Menu is for preventing the End-User from inspecting the page source. Thus, we should also disable the accelerator keys using both instructions:
webView.CoreWebView2.Settings.AreBrowserAcceleratorKeysEnabled = false;
webView.CoreWebView2.Settings.AreDefaultContextMenusEnabled = false;
since the End-User can use Ctrl+Shift-C and F12 for DevTools
check Accelerator Keys

Winform Application UI Freeze while switching between other opened application

I've developed Windows Application using C# and .Net Framework 4.5
My application loads user control and takes input from users. There are probably more than 100 controls on that user control. It works fine when I am actively using my system.
Problem is when I keep my application open and toggle to other applications which are also running e.g. checking my email, browse internet or using excel. After returning to my program, I can see the frame of my program and few controls but not all of them and I can see through my program to the last application which I visited. Also title bar of my app will become black.
Please note that my app doesn't become inaccessible. It's just won't load my all controls. I've assigned shortcut key to reload user control by which I can reload my user control and then it works fine.
I believe that your custom controls need some special drawing and this makes me think about the paint event.
Since you found a fix yourself
I've assigned shortcut key to reload user control
I believe that you can use the OnFocus event to call this shortcut key or the code behind it.

WPF SpellCheck context menu in WinForms won't extend past control

So I have an odd issue while trying to use a WPF TextBox with SpellCheck enabled inside a Winforms form, using the custom control defined in this post.
This works just fine, I've tried using it in my own sandbox project and it looks great. The problem is when I try to replace the Winforms TextBoxes inside one of our existing forms. The SpellCheck context menu is "trapped" inside the control, so all I can see are the up/down arrows of the menu.
I'm not too familiar with Winforms, as I mostly work with WPF, so I'm having a hard time determining the problem. The text box shown above is the custom control as mentioned in the linked post. The control is contained in a forms TableLayoutPanel. How can I get the context menu to expand and actually be visible?
Edit
First, to clarify, the context menu appears normally when displayed in a console application that opens the form. I did a little more testing and created a new web project (what the original problem project is) with a button that opens the form, and then the problem behavior occurs. What difference between the console application and the web application would cause this?
Edit 2
I tried the suggestions in this post, thinking maybe the context menu really was just being automatically sized incorrectly (to fit the parent control). But none of those solutions seemed to make any difference either.
Edit 3
After using snoop to look at the differences between the working context menu (windows application) and the not-working one (xbap) the only difference I could see was that the DesiredSize of the xbap instance's context menu has a smaller size, I just have no idea why.
The wpf control is a control which is hosted in winforms via the ElementHost.
Hence it lives within the area provided by the parent.
The only way is to expand it, is to change the size of the parent. Give it a try by creating a winform supersized textbox as a quick debug example. Note whether the size change works on not. If it does can the GUI accommodate that change? I can't answer that.

Webbrowser and IE acts differently?

I'm in a trouble trying to fix some problem.. I have a program with Webbrowser control inside it.
It automates crawling process from some website. The problem is that I cannot fix webbrowser after recent website changes.
They have changed page navigation on website. And when I do actions MANUALLY in webbrowser (in my app) it doesn't go to the next/previous page on website. It does nothing... Whereas it works properly in IE 7/8/9 (only scripting errors thrown this time).
So does it mean that Webbrowser is not fully similar to IE??
I'm sorry for not showing source codes here, I think it wouldn't help here. Which way should I go to troubleshoot it? Why page navigation is not working in Webbrowser control?
I tried to simply put Webbrowser on a Window Form in new project and tried to navigate page 2/3/../10 in the website catalog, but it simply changes page number and doesn't navigate to it...
EDIT: Website doesn't work propely even if I do actions manually in webbrowser using mouse clicks.. but works in IE.
EDIT2: I might be not clear in my question. The problem is that I cannot use website even Manually with mouseclicks via my Webbrowser control in app. It changes page number after I click on it, but it doesn't navigate to that page. It stays silent. I'm sure that AllowNavigation property is true. It worked just yesterday and stopped after website changes today... Please tell me which way should I go to troubleshoot it.. I thought that Webbrowser control acts the same way as Internet Explorer.. Any help from you highly appreciated! Thanks
EDIT3: Strange thing... i just loaded Extended Webbrowser and navigated to that website. Page navigation panel doesn't work there also.. Is it a bug on their side or some type of guard from crawlers? What do you think?
(http://www.codeproject.com/KB/cpp/ExtendedWebBrowser.aspx)
I'm sure this isn't the answer your want but using the webbrowser control to scrape websites is very painful to maintain.
Instead use the HttpWebRequest and HttpWebRepsonse objects to recreate the calls to the webserver.
You can use Fiddler (http://www.fiddler2.com/fiddler2) and your browser to record your web sessions and recreate them in code.
You can setup your webbrowser control to disable a number of features including navigation.
I.e. to disable nav in the C# WebBrowser control:
webBrowser1.AllowNavigation = false;
I'd double check that you're not doing anything like this.
I had the same issue with a certain web site that recently changed its format. It has to do with the version of IE used by the control.
Simply force the IE version used to the latest (in my case 9). Setting the appropriate registry item to 9999 for my application worked; see: Webbrowser control behaving different than IE

ASP.NET controls opening new windows intead of postback in same window

The fils containing these control work fine in another project and they work fine on visual studio so I guess it is safe to assume that the problem is not in the files or with the server but has something to do with the project? What could be causing this?
Only a hyperlink with target="_blank" or javascript events will open new windows.
Are you using some javascript enhancement that changes links or adds functionality to them? Could be a lightbox/shadowbox like script.

Categories