Test Menu

  • Commentary
  • Deals
  • Coupons

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)

Jun 20, 2011

ASP.NET - Read Content of File from FileUpload Control

' this code would be on the page or control and be called on some kind of action (click etc)
Dim strFileContent As String = ReadFileToString(FileUpload.PostedFile.InputStream)


' function to return file content as string from the Stream (in this case is was an html file)
Private Shared Function ReadFileToString(ByVal streamFileContent As System.IO.Stream) As String


Try


  ' read the contents of the file into a string
  Dim strFileContent As String = String.Empty


  Using sr As IO.StreamReader = New IO.StreamReader(streamFileContent)


    strFileContent = sr.ReadToEnd


  End Using


  Return strFileContent


  Catch ex As Exception
    Utilities.LogError(ex, "ParseHTML.vb.ReadFileToString")
    Return String.Empty
  End Try


End Function