Friday 18 September 2015

Small Jquery functionalities which we mostly use

//To Enable or Disable asp.net controls Using JQuery
  $('#<%=ddlstate.ClientID%>').prop("disabled", true);
  $('#<%= btnAddPopup.ClientID%>').prop("disabled", true);
  $('#<%=ddlstate.ClientID%>').prop("disabled", false);
  $('#<%= btnAddPopup.ClientID%>').prop("disabled", false);

//To remove radio button check using jQuery
   $('input[name=radio-inline]').removeAttr("checked");

//To get Radio Button Selected Value using jQuery
   var selctedval = $('input[name=radio-inline]:checked').val();

//Enable Or Disable Radio Button using jQuery
   $('input[name=radio-inline]').attr("disabled", true);   //Disable
   $('input[name=radio-inline]').attr("disabled", false);  //Enable


//Function to Enter Number only in Textbox validation
 <asp:TextBox ID="txtDuration" runat="server" MaxLength="3" onkeypress="return isNumber(event)"></asp:TextBox>

function isNumber(evt)
        {
            evt = (evt) ? evt : window.event;
            var charCode = (evt.which) ? evt.which : evt.keyCode;
            if (charCode > 31 && (charCode < 48 || charCode > 57))
            {
                return false;
            }
            return true;
        }

//Function to redirect to another page using jQuery
        function PreviousPage()
        {
            window.location = "../Training/edGlobalTraining.aspx"
        }

//Function to set radio button value OR Select Radio Button using jQuery
  RadionButtonSelectedValueSet('radio Button Name', Value

        function RadionButtonSelectedValueSet(name, SelectdValue)
        {
             $('input[name="' + name + '"][value="' + SelectdValue + '"]').prop('checked', true);
        }



//Radio Button OnClick Event in jQuery

for eg : <input type="radio" name="GenderS" id="RdbMale" onclick="return TitleBind()" value="M" runat="server" class="test" />
<input type="radio" name="GenderS" id="RdbFeMale" onclick="return TitleBind()" value="F" runat="server" class="test" />

function TitleBind()
            {
            if ($('#<%=RdbMale.ClientID%>').is(':checked')) {
                  //Function....
                }
            else if ($('#<%=RdbFeMale.ClientID%>').is(':checked')) {
                  //Function...
                }
            }

//function for previous page in jQuery
       function goBack() {
           window.history.back()
       }