Go Back
  • Javascript in the Head Section from Code Behind

    If you need to actually include a script or dynamically build a script, using variables available in your code behind:

    Dim Include As HtmlGenericControl = New HtmlGenericControl
    Include.TagName = "script"
    Include.Attributes.Add("type", "text/javascript")
    Include.InnerHtml = "alert('We added it to the head');"

    Or to include a reference to a script file:

    Dim Include As HtmlGenericControl = New HtmlGenericControl
    Include.TagName = "script"
    Include.Attributes.Add("type", "text/javascript")
    Include.Attributes.Add("src", "myScript.js")

  • Retrieving AppSettings in ASP.NET 4.0

    In some earlier projects, I had been using this way of referencing AppSettings.

    Imports System.Configuration
    Dim myVar As String = ConfigurationSettings.AppSettings("mySetting")

    This is considered deprecated in the 4.0 framework. Here is a newer way to make the same reference.

    Imports System.Web.Configuration
    Dim myVar As String = WebConfigurationManager.AppSettings("mySetting")

    This is a much simpler way than the example found on MSDN.

  • Ensuring Unique Control IDs in Sitefinity

    I had a control which used the Ajax Control Toolkit hover menu extender, but once I dragged on multiple copies of my control in Sitefinity only the first would work properly.

    When looking at the source code of my rendered page, the ID of each of the pieces of my control were identical for each instance. I believe this wouldn't be an issue outside of Sitefinity, so I turned first to the Sitefinity forum to ...

  • Displaying Version of a UserControl in Sitefinity

    There is a particular user control that I've developed that will be used on a bunch of our Sitefinity sites and is still undergoing further development. I wanted a simple way to see from Sitefinity that I am using the latest version of my control in a particular Sitefinity instance.

    Since it is common to get and set properties on a user control via Sitefinity, I thought just displaying a value without the ability to ...

  • Randomize a List

    For our school's new web template, we wanted to have a jQuery slide show which would pull from from one of Sitefinity's image libraries.

    This is a great idea, but the slide show always started on the first image of the library and would cycle through in the same order each time.

    The answer was to first randomize the content of our array before binding the DataSource to the Listview.

    Here is the Randomize Subroutine ...

  • XML Transforms (removing empty nodes)

    While dealing with some of the web services data from Digital Measures, I realized that in some cases certain nodes were included, but empty vs. simply not there. This became problematic as I was trying to alter the formatting on my output depending on what data was included in the record.

    I wanted to wrap a publication year in parenthesis i.e. (2010), but not have () sitting there empty, if for some reason no ...

  • WebResponse with Credentials

    Here is an example of retrieving some XML data that requires credentials.

    More documentation can be found on the MSDN NetworkCredential Class page.

    Public Function GetDigitalMeasuresData() As XDocument
            'get settings from web.config
            Dim digitalMeasuresUser As String = ConfigurationManager.AppSettings("digitalMeasuresUser")
            Dim digitalMeasuresPw As String = ConfigurationManager.AppSettings("digitalMeasuresPw")
            Dim digitalMeasuresServer As String = ConfigurationManager.AppSettings("digitalMeasuresServer")
            Dim digitalMeasuresPath As String = ConfigurationManager.AppSettings("digitalMeasuresPath")
            'build the URL

  • LINQ to XML

    How to: Write Queries with Complex Filtering (LINQ to XML)

    Namespaces Overview (LINQ to XML)

    A Good Select Example in VB (from HookedOnLINQ)