Using Read-Only Fields in a C# WebBrowser


I'm currently using a WebBrowser control in a C# WinForms application, and attempting to control some variability presented with this control.

Basically, my users log in to a separate UI provided by my application, which then displays the WebBrowser control, navigates to a predetermined log-in URL, and then auto-fills the username and password fields on that page.

However, in order to prevent unpredictable behavior in this WebBrowser control, I want to make these username and password text boxes read-only after they are auto-populated. Essentially, I want the user to see a browser page that has been filled out for them, and that cannot be edited. (This is so that any authentication errors can be handled by my application as opposed to the browser.)

The code I'm currently using to populate the text fields and make them read only is as follows:

webBrowser1.Document.GetElementById("username").InnerText = username; webBrowser1.Document.GetElementById("password").InnerText = password; webBrowser1.Document.GetElementById("username").Enabled = false; webBrowser1.Document.GetElementById("password").Enabled = false;

Unfortunately, when I try to make the fields read-only, the authentication server acts like the password field was not filled out, and prompts the user to fill it out again after the "Submit" button is clicked. Is this expected behavior, and if so, what other methods can I try to prevent users from changing the credentials that the browser was auto-populated with?


Try making them readonly:

webBrowser1.Document.GetElementById("username").SetAttribute("readonly", "readonly"); webBrowser1.Document.GetElementById("password").SetAttribute("readonly", "readonly");


Why don't you create a transparent panel as shown in <a href="http://www.fsmpi.uni-bayreuth.de/~dun3/archives/creating-a-transparent-panel-in-net/108.html" rel="nofollow">this article</a> which would be placed on top of the webbrowser-control:

/// <summary> /// A transparent control. /// </summary> public class TransparentPanel : Panel { public TransparentPanel() { } protected override CreateParams CreateParams { get { CreateParams createParams = base.CreateParams; createParams.ExStyle |= 0x00000020; // WS_EX_TRANSPARENT return createParams; } } protected override void OnPaintBackground(PaintEventArgs e) { // Do not paint background. } }

This would prevent the user from modifying the values.

You could show/hide this panel as you wish, and even extend to capture mouse click locations if you wished.


  • “Big” scrollbar for spinner
  • Get both date and time in milliseconds
  • Is it safe to cast void pointer to char pointer pointer
  • Java catching exceptions and subclases
  • Do stored procedures have the ability to delete a file from the OS?
  • Using self.id to populate other fields in Django
  • Read stdin in chunks in Bash pipe
  • draw pie chart using iOS quartz 2D
  • send data back from jsp iterator to struts action class
  • How to expand parent div to account for child's overflow?
  • Allocating a 2D contiguous array within a function
  • OpenCV Python: Draw minAreaRect ( RotatedRect not implemented)
  • WP7 difficulties binding data to listbox itemssource - won't refresh
  • Quick Question About Get and Set
  • Find VMID for running instance
  • Compare struct to a constant in C
  • Wrong labels when plotting a time series pandas dataframe with matplotlib
  • what makes a request a new request in asp.net C#
  • Clarification on min distance on LocationManager.requestLocationUpdates method, min Distance paramet
  • Suppressing passwd when calling sqlplus from shell script
  • Authentication in Play! and RestEasy
  • Android application: how to use the camera and grab the image bytes?
  • How to revert to previous XCode version?
  • System.InvalidCastException: Specified cast is not valid
  • Abort upload large uploads after reading headers
  • Make VS2015 use angular-cli ng at build time in a .NET project
  • Read a local file using javascript
  • QLineEdit password safety
  • Apache 2.4 and php-fpm does not trigger apache http basic auth for php pages
  • How to recover from a Spring Social ExpiredAuthorizationException
  • MySQL WHERE-condition in procedure ignored
  • Where to put my custom functions in Wordpress?
  • Web-crawler for facebook in python
  • Numpy divide by zero. Why?
  • trying to dynamically update Highchart column chart but series undefined
  • Authorize attributes not working in MVC 4
  • Busy indicator not showing up in wpf window [duplicate]
  • Python/Django TangoWithDjango Models and Databases
  • java string with new operator and a literal
  • Net Present Value in Excel for Grouped Recurring CF