Blog posts

  • Prototype innerHTML problem in Internet Explorer

    September 22, 2010 | Tags: Javascript, Troubleshooting
    This is another case of how browsers react different. Adding options to a select box would work in Firefox when using the following code:
    <select id="ourSelectBox"></select>

    <script type="text/javascript">

    $("ourSelectBox").innerHTML = "<option value='1'>test</option>";


    But in Internet Explorer the alert will display something like "test</OPTION>" and your DOM would be completely messed up.

    The solution is to use the update-function instead:
    <select id="ourSelectBox"></select>

    <script type="text/javascript">

    $("ourSelectBox").update("<option value='1'>test</option>");


    Now it should work in Internet Explorer as well!

  • IMPORTANT! ASP.NET Security vulnerability

    September 20, 2010 | Tags: ASP.NET
    Microsoft have released a Security Advisory about a security vulnerability that have been found in ASP.NET. This vulnerability exists in all versions of ASP.NET.

    Exploiting the error messages an attacker can gain access to files on the web site like for instance the web.config file.

    Read Scott Guthrie's blog post concerning this ASP.NET security vulnerability and patch your sites ASAP!

  • LINQ: Join on multiple conditions

    September 20, 2010 | Tags: LINQ, Snippet
    Here's a sample of a LEFT OUTER JOIN in LINQ using two conditions:
    MyDataContext db = new MyDataContext();
    string username = "test";

    IEnumerable<MyType> query = from c in db.MyCategories
    join s in db.MySettings on new { Username=username, CategoryId=c.CategoryId } equals new { Username=s.UserId, CategoryId=s.CategoryId } into tmp
    from ss in tmp.DefaultIfEmpty()
    orderby c.CategoryName
    select new MyType(c.CategoryId, c.CategoryName, ss.UserId == null);
    Notice the part after on:
    join alias in tablename on new { Name1=alias.Field1, Name2=alias.Field2 } equals new { Name1=alias.Field1, Name2=alias.Field2 }

    Please note that I'm mixing the conditions in my example using one value from a table and one string from the code. It's also important that you set the same names one each side of the equals

  • Copy data from another table using INSERT

    September 20, 2010 | Tags: SQL, Snippet
    INSERT INTO MyDestinationTable (MyField1, MyField2, MyField3)
    SELECT MyField1, MyField2, MyField3 FROM MySourceTable
    If your two tables have the exact same structure you may omit the list of columns in both the INSERT and SELECT sub statements, but it doesn't hurt to be explicit.

  • The best links for learning LINQ

    September 17, 2010 | Tags: Database, C#, LINQ
    The NOT IN clause in LINQ to SQL
    MSDN: Visual Basic LINQ to SQL Samples
    MSDN: 101 LINQ Samples for C#