Last Friday, I updated my browser on my Vista laptop to IE8. I then checked my web site www.JohnStagich.com 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;
bc = Request.Browser;
if (name == "IE" && bc.Version == "8.0")
if (name == "IE" && bc.Version == "7.0")
btnSend.CssClass = "txtFloatLeft";
if (name == "Firefox")
btnSend.CssClass = "txtFloatLeft";
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: QuirksMode.org.
- Here is great link from John Sheehan's blog on formatting strings.
- How to get the absolute value: Math.Abs(CInt(Textbox1.Text))
- 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.
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)
Private _ingredientsID As Integer
Private _ingredientName As String
Private _ingredientCategoryID As Integer
Public Property IngredientID() As Integer
Set(ByVal value As Integer)
_ingredientsID = value
Public Property IngredientName() As String
Set(ByVal value As String)
_ingredientName = value
Public Property IngredientCategoryID() As Integer
Set(ByVal value As Integer)
_ingredientCategoryID = value
Public Function CompareTo(ByVal other As BEIngredientList) As Integer Implements System.IComparable(Of BEIngredientList).CompareTo
- 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)
- 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
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
- How to toggle a boolean field in VB.Net: blnFlag = Not blnFlag
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.
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
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.