Test Menu

  • Commentary
  • Deals
  • Coupons

Mar 15, 2012

Reset Web Form - ASP.NET VB

Short simple procedure to clear out the textboxes and reset the dropdowns on a page.  Pass in the Page.Controls for example.



    Private Sub ResetForm(ByVal cc As ControlCollection)
        Try
            For Each c As Control In cc
                If TypeOf c Is TextBox Then
                    CType(c, TextBox).Text = String.Empty
                ElseIf TypeOf c Is DropDownList Then
                    CType(c, DropDownList).SelectedIndex = 0
                Else
                    If c.HasControls Then
                        ResetForm(c.Controls)
                    End If
                End If
            Next
        Catch ex As Exception
               ' log an error
        End Try
    End Sub

Feb 14, 2012

Simple jQuery Print Friendly Page


The following script can be used to take the content from a section of a page, in this case a div, and put the content in a new simplified window.  This is one way to exclude banners and graphics or deal with page layouts that don't  print well.  In the first section, on document ready, the link (or whatever element you like) is selected by the id "linkPrintFriendly" and assigned a function to execute when the element is clicked.  I've also made the cursor a pointer when hovering over the element.  The "printfriendly" function basically grabs html from an element on the page (with the class "theelementtoprint") and puts it in a new window that is opened.  In this example, I'm also hiding a table that I don't want to show in the new window.

I found a very useful example showing the code at http://jsfiddle.net

  <script type="text/javascript">
        $(document).ready(function () {
            $("#lnkPrintFriendly").click(printfriendly);
            $("#lnkPrintFriendly").css("cursor", "pointer");
        });

        function printfriendly() {

            //open a new window or tab
            var w = window.open();

            //include only the content of the center div or rightnocenter div
            var html = $(".theelementtoprint").html();

            //provide a title
            w.document.title = 'Page Title';

            //put the html into the new page
            $(w.document.body).html(html);

            //hide the table
            $(w.document).find("#tblFunctions").hide();

        }
    </script>

Jan 26, 2012

An Overloaded ASMX

Recently, I wanted to create an overloaded function to use in a web service.  In one of the methods, an ID will be accepted as a parameter to query records matching the ID.  In the other method, no ID is passed in and all records are returned.  Sure, I could have have given my methods different names, but what would I learn from that?  This was for an asmx.

Two areas need to be modified to have overloaded web methods.

  1. At the beginning of the service, change the web service binding from this:<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> to this: <WebServiceBinding(ConformsTo:=WsiProfiles.None)>
  2. Give the web method  a message name like this: <WebMethod(MessageName:="WithID")