Wednesday, October 1, 2014

Popup using Jquery with Ajax

<style type="text/css">
    #divPopUp {
        display: none;
        position: absolute;
        min-width: 350px;
        max-width: 700px;
        padding: 10px;
        background: #fff;
        color: #000000 !important;
        border: 1px solid #1a1a1a;
        font-size: 90%;
        min-width: 200px;
        word-wrap: break-word;
        word-break: break-all;
    }
</style>

$(function () 
    {
        var moveLeft = 20;
        var moveDown = 20;

        $(".className").hover(function (e) {
            if (($('#ContentDetails').html() != '')) {
                $('#divPopUp').show();
            }
        },
        function () {
            $('#divPopUp').hide();
        });
        $(".className").mouseleave(function (e) {
            $(#divPopUp').hide();
        });
        $(".className").mousemove(function (e) {
            $’"#divPopUp').css('top', e.pageY + moveDown).css('left', e.pageX + moveLeft).appendTo('body');
        });
    });

<div id="divPopUp">
        <h2>Heading</h2>
        <div id="ContentDetails" runat="server"></div>

</div>

Calculate Years and Months Between Dates Using C# and Javascript

C# Code

public string CalculateTenure(DateTime Hday, DateTime Cday)
{
 int Years = 0; int Months = 0;
 if ((Cday.Year - Hday.Year) > 0 || (((Cday.Year - Hday.Year) == 0) && ((Hday.Month <              Cday.Month) || ((Hday.Month == Cday.Month) && (Hday.Day <= Cday.Day)))))
{
 int DaysInHdayMonth = DateTime.DaysInMonth(Hday.Year, Hday.Month);
 int DaysRemain = Cday.Day + (DaysInHdayMonth - Hday.Day);
 if (Cday.Month > Hday.Month)
  {
   Years = Cday.Year - Hday.Year;
   Months = Cday.Month - (Hday.Month + 1) + Math.Abs(DaysRemain / DaysInHdayMonth);
  }
  else if (Cday.Month == Hday.Month)
  {
   if (Cday.Day >= Hday.Day)
   {
    Years = Cday.Year - Hday.Year;
    Months = 0;
   }
   else
   {
    Years = (Cday.Year - 1) - Hday.Year;
    Months = 11;
   }
  }
  else
  {
   Years = (Cday.Year - 1) - Hday.Year;
   Months = Cday.Month + (11 - Hday.Month) + Math.Abs(DaysRemain / DaysInHdayMonth);
  }
 }
 return Years + " Year(s) " + Months + " Month(s)";
}
  
Javascript Code 

function CalculateTenure(Hday, Cday) {
       var Years = ''; var Months = '';
       var HdayDate = new Date(Hday);
       var CdayDate = new Date(Cday);

       var HdayDateYear = HdayDate.getFullYear();
       var HdayDateMonth = HdayDate.getMonth() + 1;
       var HdayDateDay = HdayDate.getDate();

       var CdayDateYear = CdayDate.getFullYear()
       var CdayDateMonth = CdayDate.getMonth() + 1;
       var CdayDateDay = CdayDate.getDate();

if ((CdayDateYear - HdayDateYear) > 0 || (((CdayDateYear - HdayDateYear) == 0) && ((HdayDateMonth < CdayDateMonth) || ((HdayDateMonth == CdayDateMonth) && (HdayDateDay <= CdayDateDay)))))
{
  var DaysInHdayMonth = new Date(HdayDateYear, HdayDateMonth, 0).getDate();
  var DaysRemain = CdayDateDay + (DaysInHdayMonth - HdayDateDay);

  if (CdayDateMonth > HdayDateMonth)
  {
   Years = CdayDateYear - HdayDateYear;
   Months = CdayDateMonth - (HdayDateMonth + 1) + Math.floor(DaysRemain / DaysInHdayMonth);
  }
  else if (CdayDateMonth == HdayDateMonth)
  {
   if (CdayDateDay >= HdayDateDay)
   {
    Years = CdayDateYear - HdayDateYear;
    Months = 0;
   }
   else
   {
    Years = (CdayDateYear - 1) - HdayDateYear;
    Months = 11;
   }
  }
  else
  {
   Years = (CdayDateYear - 1) - HdayDateYear;
   Months = CdayDateMonth + (11 - HdayDateMonth) + Math.floor(DaysRemain / DaysInHdayMonth);
  }
 }
 return Years + " Year(s) " + Months + " Month(s)";
}


Checkbox foreach using Id in Jquery

$('input:checkbox[id^="CheckboxId"]').each(function(){
    if(this.checked) {
      // Do Actions
   }
});

$("#GridviewId input:checkbox[id$='CheckboxId']").each(function(){
    if(this.checked) {
      // Do Actions
   }

});

How to break the continuous word using CSS

p.test {
    
word-wrap: break-word;

    word-break: break-all;
}