Thursday, January 24, 2019

get RadioButtonList selected value.

You can use jQuery / JavaScript to get the selected value of a RadioButtonList . jQuery provides much more simpler approach as shown below.

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

JavaScript

var radioList= document.getElementById("<%= RadioButtonList.ClientID %>");
 var options= radioList.getElementsByTagName("input");
 var selected;
 for (var i = 0; i < options.length; i++) {
      if (options[i].checked) {
          selected = options[i];
          break;
       }
  }
  if (selected) {
       alert(selected.value);
  }

Regards,
Samitha

Wednesday, January 9, 2019

jQuery find element in a table

jQuery can be used to find an element inside a table easily as shown below.

var td = $("#tbIntervalos").find("#tdId");

cheers
Samitha

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