Test Menu

  • Commentary
  • Deals
  • Coupons

Nov 22, 2011

Databound Checklist - Check All by Default


The following code shows an easy way to loop through the list of checkboxes and select each one:


''' <summary>
''' checks all of the checkboxes by default
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Protected Sub chkListParameterSelections_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkListParameterSelections.DataBound


        Try


            For Each li As ListItem In chkListParameterSelections.Items
                li.Selected = True
            Next


        Catch ex As Exception
            ErrorLogging.LogError(ex, "ctrlStatistics.chkListParameters_DataBound")
        End Try


End Sub

Nov 10, 2011

CSS Problem After IFrame Loads

Problem: The CSS is breaking in a web page that includes an iframe in IE8 when the content of the iframe loads.  The page works fine in firefox and chrome.  Other pages without the iframe that use the same CSS file don't have the problem.

Fix: This tag was in the head: 
<meta http-equiv="X-UA-Compatible" content="IE=8" />

It was changed to: 
<meta http-equiv="X-UA-Compatible" content="IE=7" />

Nov 4, 2011

Clear All Textboxes on a Web Form

For Each ctrl As Control In Form.Controls
    If ctrl.GetType.Name = "TextBox" Then 
        Dim tb As TextBox = ctrl tb.Text = String.Empty
    End If 
 Next

Oct 5, 2011

Convert Delimited List to List(of String)

Converting a Pipe Delimited List of Values into a Generic List (of String)

Sometimes it's helpful to convert data into a different format before further processing. In this case, converting the delimited list to a generic list of string will make it more friendly for loops.


    Public Shared Function CreateSupplierList(strSupplierPipedList As String) As List(Of String)

        Try
            ' split the pipe delimited list into an array and then add to a generic list
            Dim strSupplierList() As String = strSupplierPipedList.Split("|")

            Dim lst As New List(Of String)

            For intCount = 0 To strSupplierList.Length - 1
                lst.Add(strSupplierList(intCount))
            Next

            Return lst

        Catch ex As Exception
            Return New List(Of String)
        End Try

    End Function

Aug 18, 2011

Using Lists Instead of Paragraph Tags for Lists of Links


Instead of using multiple <p> tags for lists of links use <ul> and <li> tags!

Recently, I was revising and old web page and found some quick and easy improvements to make.

This is better J

<ul class="ul">
<li><a href="page1.htm">Page 1</a> </li>
<li><a href="page2.htm">Page 2</a> </li>
<li><a href="page4.htm">Page 3</a> </li>
<li><a href="page4.htm">Page 4</a> </li>
</ul>



Than this L

<p>
  <font face="Arial, Helvetica, sans-serif" size="2"><a href="page1.htm">Page 1</a></font>
</p>
<p>
  <font face="Arial, Helvetica, sans-serif" size="2"><a href="page2.htm">Page 2</a></font>
</p>
<p>
  <font face="Arial, Helvetica, sans-serif" size="2"><b><a href="page3.htm">Page 3</a></b></font>
</p>
<p>
  <font face="Arial, Helvetica, sans-serif" size="2"><a href="page4.htm">Page 4</a></font>
</p>

Jun 30, 2011

Force Compatibility Mode in Meta Tag

Here's a nice easy way to force the page to be loaded in IE compatibility mode.

<meta http-equiv="X-UA-Compatible" content="IE=7" />

Jun 21, 2011

Calling Existing Javascript from Code Behind

Notes on how to call an existing javascript function from the code-behind.  The "confirmDelete" function below calls a jQuery dialog that will be used to delete records from a datalist.  I'm running this script from the code behind because I want to populated the dialog with values from the datalist record to allow the user to view the data they are about to delete.  The code at the bottom contained in the datalist ItemCommand method and runs when the e.CommandName = "Delete".


ASPX


<script type="text/javascript">
        // increase the default animation speed to exaggerate the effect
        $.fx.speeds._default = 400;
        function confirmDelete() {


            var dlgeditproduct = $(".deleteconfirmdiv").dialog({
                modal: true,
                width: 750,
                height: 450,
                autoOpen: false,
                title: "Are you sure you want to delete this News Release?",
                hide: "explode"
            });


            $(".deleteconfirmdiv").dialog("open");


            dlgeditproduct.parent().appendTo(jQuery("form:first"));


        };
</script>



VB


 Page.ClientScript.RegisterStartupScript(Me.GetType(), "confirmdelete", "confirmDelete();", True)