adsense

Saturday, December 22, 2018

The "SqlBuildTask" task failed unexpectedly

When using Visual Studio database projects, suddenly you will come across The "SqlBuildTask" task failed unexpectedly when building the database project.

The reason behind this error is a recent update to SQL Server Data Tools (SSDT) for Visual Studio. You can find all previous releases for SSDT here.

Cheers,
Samitha

Sunday, December 2, 2018

retrieve RadioButtonList selected value from jQuery

You can use jQery to get  RadioButtonList selected value as shown below.

var selectedVal = $('#<%= RadioButtonList.ClientID %> input:checked').val();

If you inspect the HTML DOM for a radiobutton list, you can observe that it is a set of <input type="radio"> with the same name attribute. So you can use getElementsByName to access the collection of radio buttons their index as shown below.

alert(document.getElementsByName('RadioButtonListName') [0].checked);


cheers,
Samitha


Wednesday, November 21, 2018

Adding Web Optimization framework to ASP.Net Web forms

The ASP.Net Web Optimization Framework is used to optimize the ASP.NET web application performance by reducing the number of server requests and  the size of the requested resources.


Following article explains how to integrate the  ASP.Net Web Optimization Framework to to ASP.Net Web forms project. 

When the scripts are rendered in the master page a place holder is used to wrap the rendered scripts as shown below.

<head runat="server">
    <asp:PlaceHolder runat="server">
        <%: Scripts.Render("~/bundles/jquery") %>
        <%: Styles.Render("~/Content/bootstrap") %>
    </asp:PlaceHolder>
</head>

This ensures that bundles are rendered  properly.

Cheers,
Samitha

Wednesday, October 24, 2018

Find checkbox in span using jQuery

jQuery can be used to find and checkbox inside a span as shown below.


<span class="span1" >
        <input id="chkSelect" 
             checked="checked"
             type="checkbox" /></span>

<script type="text/javascript" >
        $(function () {
            $(".span1 input[type='checkbox']").click(function () {
                if ($(this).is(":checked")) {
                    alert("Checked");
                }
                else {
                    alert("UnChecked");
                }
            });
        });
   </script >


Tuesday, October 16, 2018

check connenction from javascript

We can use javascript to check the current connection and determine if we run in local host. Here I have included the checking of custom domain name as well,


if (window.location.hostname === "localhost" || location.hostname === "127.0.0.1" || window.location.hostname.indexOf('.local') >= 0) {
    alert("Running Locally");
}

Cheers,
Samitha

Tuesday, September 25, 2018

regex to validate HH:MM AM/PM

Following regex can be used to validate HH:MM AM/PM  time format.

^([0-1]?[0-9]|2[0-3]):[0-5][0-9] [APap][mM]$

e.g
Assuming the timper control has provided class "tod"  following code will validate time when user enters a value and tabbed out/focus out from the control.

Javascript
<script  type="text/javascript">

funciton pageLoad(){
  $(".tod").focusout(function (e) {
            if (e.target.value.trim() !== "") {
                var result = checkTime(e.target.value.trim());
                if (!result) {
                   //invalid time
                }
                else {
                   //clear validation
                }
            }
            else {
                 //clear validation
            }
        });
}

function checkTime(value) {
        var pattern = new RegExp("(^([0-1]?[0-9]|2[0-3]):[0-5][0-9] [APap][mM]$)");
        var result = pattern.test(value);
        return result;
    }

</script>



cheers,
Samitha

Thursday, September 6, 2018

NuGet Package restore failed

If you ever encounter this error  delete all the related packages will resolve this.

I will further explain this using an example.

Suppose you get this error for Microsoft.Bcl.Build.Tasks.dll as shown below.

NuGet Package restore failed for project MyProject.Application: The process cannot access the file 'C:\MySolution\packages\Microsoft.Bcl.Build.1.0.21\build/Microsoft.Bcl.Build.Tasks.dll' because it is being used by another process..

This can be resolved by deleting all the Microsoft.Bcl.* folders in the packages under the solution.

Regards,
Samitha

Friday, August 17, 2018

Find an element based on data- value

There are situations where we want to find element based on data- attributes. For instance we have to set validation message at run time for a given field.

In these situations we can use jQuery to easily find an element based on the  data- atttibutes as shown below.

 $('span[data-valmsg-for="' + fieldName + '"]');


cheers,
Samitha


Monday, August 13, 2018

jQuery checkbox OnChange

We can use jQuery to identify checkbox state change as shown below.

<script  type="text/javascript">

 funciton pageLoad() //can use either DOM Ready or pagLoad
{

   const chkSelectAll= $("#chkSelectAll");

   chkSelectAll.change(function(event) {
             var chkBox= event.target;
             if (chkBox.checked) {
               //Checkbox is checked
            } else {
              //Checkbox is unchecked
           }
});

}
</script>
Cheers,
Samitha

Tuesday, July 31, 2018

Get Total Checkboxes using jQuery

Suppose there are several check boxes which are either checked or unchecked. jQury can be used to easily get the number of all check boxes, checked and unchecked boxes as shown below.

var totalCheckboxes = $('input:checkbox').length;
var totalChecked = $('input:checkbox:checked').length;
var totalUnChecked = totalCheckboxes - totalChecked ;

 

Cheers,
Samitha

Thursday, July 26, 2018

jquery Find all elements containing part of an ID

We can use jQuery to find all  elements that starts with of characters as shown below

  $("[id*=_visible_]").each(function(element){
     element.val(''); // do something with the found element.
});

Cheers,
Samitha

Thursday, July 19, 2018

Create an insert script using SELECT

There are many third party tools that provides this feature, but you can use a simple
select statement  easily create an insert script as shown belowe.

Suppose you have employee table  and want to use it to generate data for another table.


select 'insert into Table1 values(' + Id + ', ' + name + ')' from employee


Cheers,
Samitha

Thursday, June 7, 2018

SQL Server drop Unique Key script

While you can uses SSMS to easilly drop a Uniqe key, there may be situaitons where that needs to be done via a script.

Following script can be used to drop a Unique Key on a given column


IF  EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE table_name ='Employee' AND  CONSTRAINT_TYPE='UNIQUE' )
    ALTER TABLE [dbo].[Employee] DROP CONSTRAINT [UC_Employee_emp_code]
GO

Cheers,
Samitha

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