Friday, April 27, 2018

Programmatically Stop a Windows Service (Vb.Net)


You can easily start/stop a windows service using the following code snippet.


Dim service As ServiceController = New ServiceController("Service Name")
        If (service.Status.Equals(ServiceControllerStatus.Running)) Then
            service.Stop()
        End If



Cheers,
Samitha

Sunday, March 25, 2018

Nuget error while retrieving package metadata

When you try to upgrade an existing Nuget package you have might encountered the following error.

An error occurred while retrieving package metadata for 'bootstrap.3.3.5' from source 'nuget.org'

You can resolve this issue using two steps.

1. Open the packages.config from visual studio editor or notepad. Locate the line related to the corrupted package name and remove it.
2. Clean build the solution.

Cheers,
Samitha

Friday, March 2, 2018

find next table-row

When iterating though a table there are instances where we have to get the next/ previous rows.
In an earlier article I discussed how to iterate on table rows using jQuery. We can use the same code with few extra lines to get the row as shown below.

var next =$this.closest('tr').next('tr');
var prev =$this.closest('tr').prev('tr');

cheers,
Samitha

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);
 
  //gets value of span 
  var value = $this.find("span.value").html();
 
  //gets value of input 
  var quantity = $this.find("input.quantity").val();
});

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