Friday, August 28, 2009

Removing requirement for NET Framework 3.5 from setup projects

A new setup and deployment project in Visual Basic 2008 will by default require .NET Framework 3.5 on the target machine

If your application targets .NET Framework 2.0 this is a waste of time

To change the requirement right-click on your setup project, select View, Launch Conditions, go to properties of the ".NET Framework" item under the Launch Conditions node and change the Version property to 2.0.50727

Friday, August 14, 2009

How to find the control that generated a postback

Had a little trouble finding a good example of how to identify the control that generated a postback within the page_load

There's a nice article for C#, after a bit of tinkering here's a VB implementation:

Public Function GetPostBackControl(ByVal curPage As Page) As Control

 Dim foundControl As Control
 Dim controlName As String = curPage.Request.Params.Get("__EVENTTARGET")

 If (Not controlName Is Nothing And controlName <> "") Then
  foundControl = curPage.FindControl(controlName)
 Else
  ' control causing postback must be a Button or imageButton
  For Each controlName In curPage.Request.Form.AllKeys

   ' image buttons have a ".x" or ".y" appended to name string
   If (controlName.EndsWith(".x") Or controlName.EndsWith(".y")) then
    controlName = controlName.Substring(0, controlName.Length - 2)
   End If

   Dim c As Control = curPage.FindControl(controlName)

   If (TypeOf c Is Button Or TypeOf c Is ImageButton) Then
    'first button we find is the one that caused the postback
    foundControl = c
    Exit For
   End If
  Next
 End If

 GetPostBackControl = foundControl

End Function

Friday, July 10, 2009

IIS hyperlinks fail - cannot open an anonymous level security token

Recently upgraded a test machine to Internet Explorer 8. While testing a new deployment today found that hyperlinks created in my web application stopped working. The error icon on the bottom left of the screen said: "Cannot open an anonymous level security token"

The solution from a microsoft community site was to reset DCOM default properties to "Connect/Identify".

After rebooting and reopening the site in IE8 the links now work.

We tinker with DCOM on this test machine quite often and I found it with default properties of "None/Impersonate" - maybe impersonate causes a problem for anon access but I don't remember these problems with IE7. Hopefully this is not a sign the IE8 is going to "UAC" all over the system like Vista did.

Getting version number from a visual basic 2008 web application

Dim versionInfo As String = System.Reflection.Assembly.GetExecutingAssembly().GetName() .Version.ToString()

Obvious in hindsight, but took me a little while to find it

Tuesday, July 7, 2009

Changing the background color of a checkbox at runtime

I wanted to show 3 values in a checkbox ("full", "partial", and "empty") by changing background color of the selected checkbox when state is "partial"

I thought we could simply set the background color property, but that had no effect for me at runtime. It took a while to find how to programatically change background color of a checkbox on a VB web form, finally this post and this post got me close enough.

How to change the color at runtime:

(1) Add CSS style declarations to your form's design view (.aspx page), for example:

.full {
background-color: #fff;
}
.partial {
background-color: #ccc;


(2) in the form load method add some code like this:

curControl = CType(Page.FindControl(sID), CheckBox)

if (ispartial) then
curControl.Checked = True
curControl.CssClass = "partial"
else if (isfull) then
curControl.Checked = True
curControl.CssClass = "full"
etc.

Thursday, June 25, 2009

Visual Studio 2008 IDE memory leak - "Enable error correction suggestions" causes sluggish behavior, freezing, and crashes

Have been experiencing slowdowns, freezing and crashing of the visual basic IDE on a consistent basis for a few days.

I can see memory leaking in megabyte+ chunks within Task Manager each time I type anything in the IDE on a VB code page. With just one file open I can keep the memory growing indefinitely in ~10MB increments by adding any text, erasing it, saving, and then repeating.

The additional memory is not fully recovered so I eventually have to restart the IDE to avoid a crash. I've seen it climb up to 1.4 GB (out of 3 GB). This was not a sustainable way to work.

Almost sure this behavior started after June 2009 windows hotfixes were applied. I had been working primarily in Java/Eclipse the last few months, but intermittenly spent time in the VS2008 IDE producing hotfixes and had not experienced this instability before.

Tried removing Office 2007 (trial) since that was mentioned as a possible issue in a couple of places, but no change. Tried removing MS Works which was recently installed as a "security hotfix" - only to find that is a whole can of worms by itself.

WORKAROUND: What finally seems to have stabilized the IDE is de-selecting the "Enable error correction suggestions" option.

HOW TO: to de-select this option go to Tools, Options, Text Editor, Basic, VB Specific - uncheck the box and hit OK.

If anyone has any better suggestions please feel free to post in comments.

Thursday, April 23, 2009

Using "Zone" as a field alias in SQL query generates getDescription error 80004005

Spent a few minutes on this one and it seemed worth noting. I was trying to run a query joining a few tables using field aliases (e.g. tbl_X.fieldY AS aliasZ) because each table has an fName field that I need to reference.

The query generated an error: IErrorInfo.GetDescription failed with E_FAIL(0x80004005)

At first I thought it as a DCOM permissions issue, since error code 80004005 can indicate an insufficient security permissions when accessing resources using COM. However, it turns out my alias tbl_Zone.fName as Zone" was the problem.

Apparently Zone is a reserved word in this context? Who knew.