Archive for March, 2010

Winforms MultiLine TextBox Background Colour Is Dark Grey On Vista Only

March 8, 2010


I am maintaining a Winforms app. My DEV machine is running XP, but my user is running Vista. Within a GroupBox I added a multiline TextBox and styled it to look like a Label by setting BackgroundColor of the Textbox to System.Control in the Visual Studio Properties of the Textbox and making the TextBox borderless. The Textbox rendered nicely in XP but on Vista the Background colour was rendered as Dark Grey instead of the colour System.Control.

To try and force Vista to render the TextBox background as the colour System.Control, I found out what the RGB Values are for the colour System.Control and set the TextBox Background to that value in the Page Load event. This did not work.

After some Googling I located a couple of posts on the issue which indicated that there is some bug relating to rendering of Multiline Textboxes in Winforms:

Black Background Appearing In ReadOnly TextBox For An Application In Vista Machine

Multiline Textbox With Vertical ScrollBar In A SplitContainer On A TabControl In Vista

This self-explanatory post from Code Project, How To Make A TextBox/RichTextBox Transparent was reported by some correspondents to help them work around the Vista rendering issue.

Demetres Zarkadoulas in this Windows Developer Centre Forum post crystallized the issue: Problem With TextBoxes And Transparent Group Boxes In Vista

This seems to be a problem of the textbox in any transparent container in Vista.

Armed with hints from the links above I added a few different multiline TextBoxes with varying Properties to my Form to see which styles would render the Background Colour correctly under Vista. I found there were a several ways to solve the problem:

  1. Move the Multiline TextBox out of the GroupBox
  2. Give the TextBox a border (BorderStyle 3DBorder will do it)
  3. Use TransparentRichTextBox (add it to your GroupBox dynamically in Code-Behind)
  4. Put the TextBox on top of a Panel (This is what I ended up doing.)

So, if you’ve got a MultiLine TextBox inside a GroupBox on Vista and the Background Colour renders Dark Grey or doesn’t render to the shade you want, do any of the above.


External Javascript Source File Syntax Error Code 0 Line 1 Char 1

March 2, 2010

Our maniacally thorough Web Designers found a bug on one of our Web Pages related to a Javascript file. In IE with ‘Show All Errors’ checked in Internet Options it reported blah.js syntax error code 0 line 1 char 1.

Looking into the error I determined that it only occurred on our PROD Web Server, which meant that there was no real problem with the Javascript file. Just to see if it was a cross-browser issue I loaded the offending page in Firefox and was immediately rewarded with a whole truckload of additional information via Tools -> Error Console

Lesson #1 – Debug your Web Page in Firefox. You get much better and much more debug information out of it.

The Firefox Error Console told me that the offending URL was and that the offending line of source code was a DOCTYPE definition, like so: !DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN”

But the rest of the source file was not the blah.js file, but our Custom 404 (File Not Found) Page from the Web Server. So, looks like blah.js could not be found.

Examining the aspx page, blah.js was being loaded as an external javascript file:
script src=”/script/blah.js” type=”text/javascript”.

Now, I don’t have access to the live Web Server, but the Engies confirmed for me that there was no folder named ‘script’ in the IIS Directory for, so naturally src=”/script/blah.js” did not exist. I asked them to edit the external script reference for blah.js to a Hotlink I knew was valid, like so
script src=”” type=”text/javascript”.

Tomorrow, after they do it, I’ll tell you if that fixes the problem. I’ll bet you one slightly damaged Ferrett that it works.

This Condition Is Caused By…

The path to the external blah.js in the src attribute of the script tag on the aspx page was non-existent, giving a bad URL. The HTTP Request that served the script returned 404 for giving back our Custom 404 Page. The first line of that page is DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN”. That line is not valid javascript hence the syntax error reported by both IE and Firefox.

This Stack Overflow thread, Doctype Error With Google Maps put it all together for me, many thanks to Stack Overflow User #176492 Mike Williams You are much more than a number to me.

Update 3-Mar-2010: Firebug Rocks

I’m a little closer to solving the whole puzzle now.

Using the amazingly useful Firebug I was able to inspect the HTTP Result Codes in its Net Panel. This showed me that /scripts/blah.js got a 404 on our DEV server but a 200 (OK) on our PROD Server. That 200 is not a real 200 of course, but a Soft 404.

Checking Web.Config I found that customErrors is set to On and that it returns our custom Page “custom404.aspx” for a 404 error. The first line of that page is !DOCTYPE etc. Below is a sample customErrors entry so you know what I mean. More info from Milan Negovin here at ASP.NET Resources

customErrors mode="On" defaultRedirect="~/errors/GeneralError.aspx"
error statusCode="404" redirect="~/errors/custom404.aspx" /

Didn’t check DEV Web.Config yet. I’ll bet customErrors are off or 404.aspx does not exist on that server. Double or nothinng on the Ferretts ?

And just for fun here’s Google’s list of best 404 pages.

Credentials Property Missing From WebService Instance

March 1, 2010


You are eating your liver because you have created an Instance of a Web Service which exists in your local project and you want to add custom Credentials to the proxy Instance BUT there is no Credentials property.

So Pretty, So Useless

Your code looks flawless: It looks something like this, but Visual Studio reports there is no Credentials property

_MyWebService = New XMLExtractWebService

What You Need To Do

Add a Web Reference to the Web Service i.e. Click on the WebReferences folder in the project which is consuming the Web Service and select Add Web Reference. Click on ‘Web Services In This Solution’ and then select your Web Service. Add a Reference name for it. I called my reference MyXMLExtractWebService.

Now update your code as follows, giving the class name of your Web Reference:

_MyWebService = New MyXMLExtractWebService.XMLExtractWebService

Your Credentials Property is now there.

Why It Works

The Credentials Property only exists on Web Services deriving from created using the Web Services Description Language (WSDL) tool (Wsdl.exe), or created when adding a Web Reference in Visual Studio.NET,

These Web Services derive from the SoapHttpClientProtocol class and have a Credentials property, which can be used to get or set security credentials for Web Service client authentication.

For this wisdom we can thank Madhu in this post in the .NET 247 Forum