Click here to Skip to main content
15,886,637 members
Articles / Web Development / ASP.NET
Tip/Trick

Some Important Findings - Web Applications: Part II

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
17 Jul 2012CPOL1 min read 6.6K   3  
Continuing from last upload about some useful findings

Introduction

I am sharing some important findings I got from some of my earlier work. Hope these will help some of my developer friends and also help me in summarizing findings for my work in the future.

Using the Code

  1. When Button is disabled in page_load, then its onclientclick is not rendered.

    Suppose you have a button and it specifies ‘OnClientClick’ value but as per your logic you have disabled it from server side (loading stage).

    After this, you will face either of the following scenarios:

    1. If ‘OnClientClick’ value was specified either in mark up or will happen (set) always and you are enabling the disabled button after a post back, then everything will work properly.
    2. If you are enabling the disabled button from client script, then the client handling part of that button will not work.

      For resolving the above point, either follow:
      1. Point (i.)
      2. Disable the button not using the ‘Enabled’ property but through HTML attributes (disabled = ‘disabled’)
      3. Ensure you attach the ‘onclick’ (client script) to your button once you enable it back

  2. Using ‘$.inArray

    We use this method to determine whether something exists in the specified array or not but many times it fails to return the expected result. The main cause is with the type of input demanded. Consider the below example:

    JavaScript
    $(document).ready(function () {
               var arr1 = new Array();
               var arr2 = new Array();
               var arr3 = new Array();
    
               arr1["one"] = "1";
               arr1["two"] = "2";
               arr1["three"] = "3";
    
               arr2[0] = 1;
               arr2[1] = 2;
               arr2[2] = 3;
    
               arr3["0"] = "1";
               arr3["1"] = "2";
               arr3["2"] = "3";
    
               alert($.inArray("2", arr1)); // returns -1
               alert($.inArray(2, arr2)); // returns 1
               alert($.inArray("2", arr3)); // returns 1
               alert($.inArray(2, arr3)); // returns -1
           });
    
  3. Wrapping text in any HTML parent tag. I used one CSS property (CSS 3) for ensuring that text is wrapped within a DIV.

    JavaScript
    style="word-wrap:break-word;"

    It will ensure that it breaks all long words and wraps onto the next line.
    However since it is specific to CSS3, while using Visual Studio, you may face some warnings but it works well in all major browsers.

History

  • 15/07/2012: First revision

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --