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