Thursday, February 8, 2018

jquery using same event for multiple classes

You can attach same event for multiple css classes as displayed below.

<script type='''text/javascript">

function OnClicked(){
    if ($(this).hasClass('tag1')){
        // code
    }
    else {
         // code
    }
}

  $(function() {
    //method 1
     $(".tag1, .tag2").click(OnClicked);

         //method 2
        $(".tag1, .tag2").click(function(){
            alert("clicked");   
        });​








});

</scrip>

Regards,
Samitha

Friday, January 26, 2018

Iterate a table rows with JQuery

 HTML table can be easily iterated using jQuery as shown below. The trick is to use a class for each row and iterate using $("tr.item") selector. 
Also note that $this.find is used to get value of a given table cell.


HTML
  <table>
 <tr class="item">

    <td> cell1 </td>
    <td> <span class="value">25.00 </span> € </td>
    <td> <input type="text" value="15" class="quantity" /> </td>
   </tr>
   <tr class="item">
    <td> cell2 </td>
    <td> <span class="value">50.00 </span> € </td>
    <td> <input type="text" value="16" class="quantity" /> </td>
   </tr>
</table>
 


JavaScript
 $("tr.item").each(function() {
  $this = $(this);
  var value = $this.find("span.value").html();//gets value of the span
  var quantity = $this.find("input.quantity").val();;//gets value of the input
});

Thursday, January 18, 2018

Retrieve button value

You can use jQuery val() function to retrieve buttons' value as shown below.

HTML

<button class="btn1"  name="btn1" value="button1">
    Label</button>

JavaScript

<script type="text/javascript">
    $(function() {
        $('.btn1').click(function() {
            alert($(this).val());
        });
    });
</script>


 This will display the value button1.

Regards,
Samitha

Wednesday, December 6, 2017

.NET Support for TLS 1.2

It seems that support for TLS 1.2 dependent on the .net framework version.

  • NET 4.6 and above. Supported by default.
  • .NET 4.5. TLS 1.2 is supported. The following code will make TLS 1.2 to be used as the default protocol.                                                                  ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
  • .NET 4.0. TLS 1.2 is not supported, but following code can be used as a workaround:
    ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
  • .NET 3.5 or below. TLS 1.2 is not supported.
Cheers,

Samitha

Thursday, November 16, 2017

Removing XML Nodes from a XML Document

Following code can be used to remove a XmlNode with all the children nodes

      XmlDocument doc = new XmlDocument();
        doc .Load(MapPath("~/FileName.xml"));
        XmlNodeList selectedNodes = doc .SelectNodes("//SubNode");
      
       foreach (XmlNode node in selectedNodes )
        {
            node.ParentNode.RemoveChild(node);
        }

Regards,
Samitha

Thursday, November 2, 2017

IIS error accessing WCF (HTTP Error 404.3)

When accessing a WCF service through browser, you  might have encountered following IIS error.

HTTP Error 404.3 - Not Found The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.

This occurs due to a feature in IIS which is not turned on by default.


This issue can be solved through following steps.

  1. From Control Panel -> Programs and Features -? Turn Windows features on or off.
  2. Click.NET Framework 4.6 Advanced Services - WCF Services (actual framework version may change)
  3.  Select HTTP Activation
  4. Ok

 

Wednesday, October 4, 2017

jquery paste event

You can use the jQuery paste event on any textbox/editor as shown below. It is supported by all modern browsers.

Following example shows handling numeric values on key press and past.

 <script type="text/javascript">

 function pageLoad() {
  $("#controlID").on('paste, keydown', function e() {
        return isNumericKey(e);
  });
 }
 
function isNumericKey(e) {
    var charInp = window.event.keyCode;
        if (charInp > 31 && (charInp < 48 || charInp > 57)) {
            return false;
        }
        return true;
  }
 
</script> 
 
Cheers,
Samitha