Friday, 13 December 2013

swapping/changing image of image button in javascript on ClientClick

//// set value = "expand" in your image button tag, get this value to swap image randomly.

function swapimagesrc()
    {
      if(document.getElementById("imgbuttonExpand").value =="expand")
      {
         document.getElementById("imgbuttonExpand").src = '../CRMImages/close_view.fw.png';
         document.getElementById("imgbuttonExpand").value = "close";
      }
      else if(document.getElementById("imgbuttonExpand").value =="close")
      {
          document.getElementById("imgbuttonExpand").src = '../CRMImages/expand_view.fw.png';
            document.getElementById("imgbuttonExpand").value = "expand";
      }
    }

Validating file uploader in Javascript

function ValidateFile()
    {
      var validFilesTypes=["bmp","gif","png","jpg","jpeg","doc","xls"];
      var file = document.getElementById("<%=fileupload.ClientID%>");
      var path = file.value;
      var ext=path.substring(path.lastIndexOf(".")+1,path.length).toLowerCase();
      var isValidFile = false;
      for (var i=0; i<validFilesTypes.length; i++)
      {
        if (ext==validFilesTypes[i])
        {
            isValidFile=true;
            return true;
        }
      }
      if (!isValidFile)
      {
         alert('File Format is invalid.["bmp","gif","png","jpg","jpeg"] are allowed.');
         return false;
      }
    
     }   

Getting Querystring values from javascript

function ShowGridDivsonload(objID)
    {
        var qsarr = new Array();
        var qs = location.search.substring(1);
        var singleqs = new Array();
        var str ="";
        qsarr = qs.split('&');
        for( i=0; i<qsarr.length; i++)
        {
            singleqs = qsarr[i].split('=');
            str = singleqs[1]  ;
        }
           if( str == "HS")
           {
             $("#"+objID+" div").show();
             $("#"+objID+" a[Anchor] ").text("-");
             document.getElementById("imgbuttonExpand").src = '../CRMImages/close_view.fw.png';
             document.getElementById("imgbuttonExpand").value = "close";
           }
    }
   

Tuesday, 17 September 2013

Sorting Of The Gridview column without using Datasource

 protected void GVinsurance_onSorting(object sender, GridViewSortEventArgs e)
        {

            DataTable dt1 = (DataTable)ViewState["DT"];//GVProvider.DataSource as DataTable;
            if (dt1 != null)
            {

                if (dt1 != null)
                {
                    DataView dvSortedView = new DataView(dt1);

                    dvSortedView.Sort = e.SortExpression + " " + getSortDirectionString(e.SortDirection);

                    GVInsurance.DataSource = dvSortedView;
                    GVInsurance.DataBind();
                }

            }
        }

----------------------------------------



 private string getSortDirectionString(SortDirection sortDirection)
        {
            string newSortDirection = String.Empty;

            if (Convert.ToString(ViewState["newSortDirection"]) == "DESC")
            {
                ViewState["newSortDirection"] = "ASC";
            }
            else
                ViewState["newSortDirection"] = "DESC";

            return newSortDirection = Convert.ToString(ViewState["newSortDirection"]);
        }


Wednesday, 17 July 2013

Validating number of characters before and after decimal point using javascript

  function validatemaxAmt(sender, evt)
{
              var splitValue = sender.value.split(".", 2);

        
                  if(splitValue[0] != null)
                 {
                    if(splitValue[0].length < 7)
                    {
                       // alert("Correct format.");
                        return true; // allow postback (if applicable)
                    }
                    else
                    {
                        alert("Incorrect number of decimal digits.");
                        sender.value="0";
                        sender.focus();
                        return false; // disallow postback (if applicable)
              
                    }
                }
}

Wednesday, 26 June 2013

Handling the radio button list with yes or no confirmation message in C#


rdbbilltype.Attributes.Add("onclick", "if(!confirm('Are you sure to change the bill type? ')) return false;");



Looks simple but it will allow only when the OK button is clicked, Or else it wont change the selection.

Awesome...!!!

Monday, 17 June 2013

Javascript validation for special characters in ASP.NET/ C#

function validatespecailchars()
{

     var txtbox = document.getElementById('<%=txtsearch.ClientID %>').value;
   
      var str="<";
        var str1=">";
        var str2="--";
        var str3=";";
        var str4="'";

    if((txtbox.indexOf(str)>=0)||(txtbox.indexOf(str1)>=0)||(txtbox.indexOf(str2)>=0)||      (txtbox.indexOf(str3)>=0)||(txtbox.indexOf(str4)>=0))
    {
         alert('Special Characters are not Allowed.');
        // you can focus here that particular control
     }
}