John Stagich's Blog

Microsoft .Net Developer

IE8 and Browser Compatibility

clock April 20, 2009 08:34 by author johnstagich

Last Friday, I updated my browser on my Vista laptop to IE8.  I then checked my web site with the new browser.   Three of my web pages did not render as they did with IE7.  After spending a good amount of time tinkering with CSS style sheets and the like, I finally was able to get the web pages to look “similar” in IE7, IE8, and Firefox 3.0.8.  What a hassle.  Here is some of the code I used to achieve the similar look:

        var name = Request.Browser.Browser;

        HttpBrowserCapabilities bc;

        bc = Request.Browser;


        if (name == "IE" && bc.Version == "8.0")


            btnSend.Style.Add("margin-left", "205px");


        if (name == "IE" && bc.Version == "7.0")


            btnSend.CssClass = "txtFloatLeft";

            btnSend.Style.Add("margin-left", "172px");


        if (name == "Firefox")


            btnSend.CssClass = "txtFloatLeft";

            btnSend.Style.Add("margin-left", "152px");


I then read an article in Computerworld about browser compatibility.  It turns out that Microsoft is making an effort with IE8 to make it much more World Wide Web Consortium (W3W) compliant then previous versions of Internet Explorer.  Hence, the rendering changes of my web site with IE8. 

One developer in the article suggests devloping your web code first with Firefox and then making the necessary adjustments for the IE browsers.

If you are interested in finding out more about the differences between browsers, here is a good reference that contains compatibility tables for the different browser versions:



April 2009 Quick Hits

clock April 13, 2009 12:17 by author johnstagich
  • SQL 2008 "Features"
While making minor modifications to a table, I would get an error when I tried to save.  To fix, go to Tools->Options->Designers->Table and Database Designers and uncheck the Prevent saving chages that require table re-creation in the Tabel Options Group Box.

IntelliSense cache needs to be manually updated after modifying tables. I discovered this "feature" after adding a rowguid column to a table.  I then tried to run an automated "Select All Rows" query, and intellisense errors apppeared in the query.  I was able to run the query successfully however.  The problem was that the IntelliSense cache needed to be updated.  It did not have the information about the new rowguid column.  To update Intellisense Cache, go to Edit->IntelliSense->Refresh Local Cache (Ctnl+Shift+R).  For more information, check out this link:

  • Here is a link to a to a three part series of articles from Bill Ramos on degugging T-SQL in Microsoft SQL Server 2008.

  • From tip number 56 Tips & Tricks for ASP.NET, IIS, and Visual Web Developer:

    1) From the keyboard: Ctrl+Shift+J will do it.  Wait for "Updating Intellisense..." message on status bar, then try invoking Intellisense again.
    2) From the menu: Select Edit menu, then Intellisense->Update Java Script Intelllisense.  Again, wait for "Updating Intellisense..." message on status bar, then invoke Intellisense. 

  • Want to Learn about PowerShell?  Here is a link to Idera's Practical PowerShell Video Series.

  • From Scott Mitchell's blog, a series of tutorials on ASP.Net Hosting.

  • Here is a query to get a row count from each table in your database:

--Get all table names


Select Name into #tableNames from sysobjects where xtype = 'U' order by 1

Create Table #TableCount (TableName Varchar(100), NoOfRowCount bigint)

declare @name varchar(100)

--declare a cursor to loop through all tables

declare cur cursor for select * from #tableNames

open cur

fetch next from cur into @name while @@fetch_status=0


Insert #TableCount

exec ('select ''' + @name + ''' , count(1) from ' + @name)

print 'Fetching count of table : ' + @name

fetch next from cur into @name


close cur

deallocate cur

--show the data

Select * from #TableCount drop table #tableNames

drop table #TableCount


March 2009 Quick Hits

clock March 9, 2009 13:20 by author johnstagich


from syscolumns

left join sysobjects on =

where like '%guid%'

order by 1,2

February 2009 Quick Hits

clock February 5, 2009 08:28 by author johnstagich
  • Here is great link from John Sheehan's blog on formatting strings.

  • How to get the absolute value:  Math.Abs(CInt(Textbox1.Text))

January 2009 Quick Hits

clock January 24, 2009 09:52 by author johnstagich
  • How to include Find Combo from Standard Toolbar in Visual Studio 2008

In my Visual Studio IDE, the Find Combo box disappeared from my Standard Toolbar.  Here is how you get it back.

1) Right Click the Standard Toolbar
2) Select Customize ...
3) Drag and drop the "Edit | Go To Find Combo" from the "Commands" tab to the Standard Toolbar

  • Problem with DataGridView automatically adding columns from DataSource during design time.

Fix: Clear the DataSource property for the DataGridView.  Add the DataSource back if you want to add columns.  Check out this link for some background information.  Here is where I found out about the fix

December 2008 Quick Hits

clock December 26, 2008 11:06 by author johnstagich

The key here is implementing the IComparable interface when creating your class (see link above for more information).  The IComparable interface has the CompareTo method that does the sorting. Once the interface is in place, you can use the sort method in the generic list: to sort your list (GenericList.Sort()).  Here is some sample code that implements the IComparable interface to an Ingredients Generic list.  To sort this list by IngredientID, instantiate the class (Dim objIngredientList as List(Of BEIngredientList = New List(Of BEIngredientList)}, popluate the list, and then excute the sort method objIngredientList.Sort().

  Public Class BEIngredientList 
   Implements IComparable(Of BEIngredientList)
#Region "Locals"
    Private _ingredientsID As Integer
    Private _ingredientName As String
    Private _ingredientCategoryID As Integer
#End Region
    Public Property IngredientID() As Integer
            Return _ingredientsID
        End Get
        Set(ByVal value As Integer)
            _ingredientsID = value
        End Set
    End Property
    Public Property IngredientName() As String
            Return _ingredientName
        End Get
        Set(ByVal value As String)
            _ingredientName = value
        End Set
    End Property
    Public Property IngredientCategoryID() As Integer
            Return _ingredientCategoryID
        End Get
        Set(ByVal value As Integer)
            _ingredientCategoryID = value
        End Set
    End Property
    Public Function CompareTo(ByVal other As BEIngredientList) As Integer Implements System.IComparable(Of BEIngredientList).CompareTo
        Return Me.IngredientID.CompareTo(other.IngredientID)
    End Function
End Class


  • Computed Columns with Microsoft SQL 2005

    Select the table to which you want to add a computed column. From the Design screen, select the column name (in the example below we use a column called PreparedDryWeight).  Next, in the Column Properties screen expand the Computed Column Specification.  Enter the formula  into the (Formula) field as shown in the example below.
    (case when [PreparedMoisturePercentage]>(0) then [PreparedNetWeight]-[PreparedNetWeight]*([PreparedMoisturePercentage]*(0.01)) else (0) end)

    Note: You cannot use another computed column in the calculation.  Check ou this link The Power of SQL Case Statements by Scott Mitchell

  • Refining a value from a Date data type field using the Value property .

    obj.DryingDate.Value.Date   -Get the Date as Date data type
    obj.DryingDate.Value.Year   -Get the Year as Integer data type

  • Return a DataSet object type with Enterprise Library.  The key is the database.ExecuteDataSet(dbCommand) method.  See sample code below.

    Public Function GetDistinctBatchProductDesc(ByVal statusID As Integer, _
                                                    ByVal receivingLocationID As Integer) As DataSet
            Dim ret As New DataSet
            Dim db As Database = DatabaseFactory.CreateDatabase("SQLDataAccess")
            Dim sqlCommand As String = "Inventory.GetDistinctBatchProductDesc"
            Dim dbCommand As Common.DbCommand = db.GetStoredProcCommand(sqlCommand)
            db.AddInParameter(dbCommand, "StatusID", DbType.Int32, statusID)
            db.AddInParameter(dbCommand, "ReceivingLocationID", DbType.Int32, receivingLocationID)
            ret = db.ExecuteDataSet(dbCommand)
            Return ret
        End Function

  • WPF Videos

  • Preventing Users from Leaving Invalid Controls in Windows Forms.

    In a Validating event handler, you can prevent users from leaving the control containing the invalid entry until they clear or fix the error. If you look back to the code that assigned the event handler to the control, you will note that it wrapped the method in a CancelEventHandler. That provides the flexibility to add this line in the handling routine.

    e.Cancel = true; 

    ' Sample code that checks to make sure a textbox control contains text.

    Private Sub txtTypeCode_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtTypeCode.Validating
            If Not Regex.IsMatch(txtTypeCode.Text, "\w") Then
     MessageBox.Show("Type Code CANNOT be blank", "Input Error", MessageBoxButtons.OK,           MessageBoxIcon.Error)
                ' Prevents users from leaving textbox until they fix it!
                e.Cancel = True
            End If
    End Sub

    That line of code suppresses any events that would normally follow the Validating event.  To users, the code causes the cursor to remain stubbornly in the control; neither tabbing nor mousing will get it to budge until the user corrects the error.  For more information on the Validating event, see this MSDN article.

  • How to make input parameters optional in T-SQL. Place an "=" sign after the datatype, and then assign a DEFAULT value.

    Create Procedure OptionalParametersDemo
       @floatTest      float=Null,
       @varcharTest varchar(10)=Null,
       @dateTest     datetime=Null,
       @intTest        int=Null
    As ...

  • How to toggle a boolean field in VB.Net:  blnFlag = Not blnFlag

Enterpirse Library Cryptography Error

clock November 22, 2008 08:39 by author johnstagich

I was using the Cryptography portion Enterprise Library 3.1 for the encryption and decryption of data in my Windows application.  Part of the configuration process creates a key file (*.key) necessary for the encryption/decryption to work.

 It was all working fine until I tried to publish and deploy the application. The cryptography piece would not work when the application was deployed to another machine. Here is why. The algorithm that builds the key file uses local machine information to build the key.  When the key file is placed on another machine, the machine information is different; consequently the cryptography fails with the following error message: "Key not valid for use in specified state. \r\n" Source="System.Security" 

 How do you fix this problem?


1)      Create a password protected text version of the key file (for example, AppKey.txt). Use the Enterprise Library Application Configuration tool to create a text version of the key file (for example, AppKey.txt).

2)      When deploying your application, make sure you deploy the text version of your key file (AppKey.txt) and not the key file (AppKey.key).

3)      In your application, at start-up, add the following code I found on codeplex (see DevLingo entry July 17, 2007).  The code reads the text file (AppKey.txt) and recreates the key file (AppKey.key).  It then updates the app.config file, to point to the location of the new AppKey.key file.


clock November 21, 2008 09:10 by author johnstagich

At last night's Memphis .Net users group meeting, Mark Mydland from Microsoft talked about the up and coming enhancements to the testing portion of the next version of Visual Studio Team System. One of the new features that I liked was the ability to record a test sequence.

Another topic discussed was PEX.  It is a new product from Microsoft Research.  From the web page:

Right from the code editor, Pex finds interesting input-output values of your methods, which you can save as a small test suite with high code coverage. Pex performs a systematic analysis, hunting for boundary conditions, exceptions and assertion failures, which you can debug right away.

November 2008 Quick Hits

clock November 8, 2008 13:42 by author johnstagich
  • Enterprise Library 3.1: Enterpise Library Configuation Editor Problem

An application I was working on needed to run on with the Entiprise 3.1 Library.  When I tried to use the Enterprise Library Configuration editor (EntlibConfig.exe) on my app.config file, I was getting errors that it could not locate the specific libraries/.dll’s.  The problem was that my libraries in my code where strongly named (PublicKeyToken=b77a5c561934e089) while the Enterprise Library Configuration Editory was looking for libraries with the PublicKeyToken set to null (PubliKeyToken=null).  The fix was to use the RIGHT Enterprise Library Configuration editor.  There are two of editors.  One resides in C:\EntLib3Src\App Blocks\bin and the other resided in  C:\Program Files\Microsoft Enterprise Library 3.1 - May 2007\Bin.  The former works with non-signed libraries while the latter works with signed libraries.  From the Visual Studio Development environment, I changed app.config editor to point to the C:\Program Files\Microsoft Enterprise Library 3.1 - May 2007\Bin editor.

For more information, check out this link from Tom Hollander on Avoiding Configuration pitfalls with incompatible copies of Enterprise Library.

  • How do you debug a Unit Test in Visual Studio 2008?

1) Set a breakpoint in your test, and then from the Visual Studio menu: Test-->Debug-->Tests in Current Context.

2) Set a breakpoint in your test. Go to the Test Results window (from the Visual Studio menu: Test-->Windows-->Test Results).  From the toolbar in the Test Results window, click on Debug drop down icon and then select Debug Checked Tests.

3) Try entering System.Diagnostics.Debugger.Launch() and System.Diagnostics.Debugger.Break() into your Unit Test code and then run your Unit Test  You then will be prompted with a Visual Studio Just-In-Time Debugger dialog box.  Select the default selection.  You should then break into your Unit Test code.

  • Here is a good link to the How Do I Video Series for Visual Basic.
  • For the datagrid view control, if you want the NewRowNeeded event to fire, the VirtualMode property for the datagrid view control needs to be set to true.
  • From Scott Mitchell's blog, I found out about a product called ELMAH that may come in handy down the road.  ELMAH (Error Logging Modules and Handlers) is an application-wide error logging facility that is completely pluggable. It can be dynamically added to a running ASP.NET web application, or even all ASP.NET web applications on a machine, without any need for re-compilation or re-deployment.
  • Have you ever wanted to share a common file among project? Check out Sara Ford's tip number #365 that shows how to link a file. (I wonder how this works with Team Foundation Server Source Control?).  Tip number #364 is good too.  Visual Studio comes with an image library.

  • FromScott Gu's blog, new ASP.Net Chart control.

  • The table designer in Microsoft SQL 2005 I find is lacking because I cannot find a way to add properties to the columns displayed.  It only displays Column Name, Data Type, and Allow Nulls.  From Rich Strahl's Web log, comes a work around.  Use the Database Diagram Designer.   Right mouse click on the Database Diagrams folder and click New Database Diagram.  Next add your table.  Right mouse click on the table-->Table View-->Modify Custom...

October 2008 Quick Hits

clock October 1, 2008 08:43 by author johnstagich
  • SQL Server 2005: Reporting Server Error 1053-The service did not respond to the start or control request in a timely fashion

I am now starting to work with Microsoft Reporting Services (SQL 2005).  The SQL Server Reporting Services service would not start.  It looks like one of the Hot Fixes for SQL 2005 mucked something up.  Anyway, it required a registry fix and a reboot.  Here is the link  

You may want to check out this link also

  • Enterprise Library 4.0: Getting Exception Handling and Logging to Work

I have been working with the Enterprise Library 4.0 extensively.  I  had already implented the Data Access and Cryptography application blocks with no problems.  However, I did run into problems with the Exception Handling and Logging Application blocks.  In order to get the Exception Handling to log a message to the Application Event log, I had to add a reference to the Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.Configuration.Design.dll (Enterprise Library Exception Handling And Logging Application Block Design) library.  In order to get the Exception Handling to log to the Database, I had to add a reference to the Microsoft.Practices.EnterpriseLibrary.Logging.Database.dll (Enterprise Library Logging Application Block Database Provider) library.  Both of these references were not mentioned in the documentation that I was using.

  • Windows Forms: Controlling Event Firing

While working on a Windows application, the SelectIndexChanged event with the ComboBox control was firing unintentionally. I only wanted the event to fire when the user changed the value in the combo box. Doing some research, I was presented with two options (see link). One, use a boolean flag to monitor what was causing the event to fire. The second was to remove and add the SelectIndexChanged event handler for the ComboBox at appropriate times in your code. I chose the latter. It really is quite simple.

Remove Handler: RemoveHandler comboBoxProduct.SelectedIndexChanged, AddressOf comboBoxProduct_SelectedIndexChanged

Add Handler: AddHandler comboBoxProduct.SelectedIndexChanged, AddressOf comboBoxProduct_SelectedIndexChanged

  • ASP.NET Website Development - Displaying Images from SQL Server Database

I picked this information up from a David Hayden blog post.  I had a project at a former employer where this code could have come in handy.  I can imagine possibly getting a similar request to display images from an SQL database in the future.  Here is the link


About the author

I am the owner of Stagich Software Consulting.  Stagich Software Consulting specializes in developing Microsoft .Net/Microsoft SQL software applications.



<<  January 2015  >>

View posts in large calendar

Month List

Category list



The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

Sign In