DNK Gif

Dot Net Knowledge

Labels

Sunday, 6 September 2015

Get Query String Value using JavaScript

How to get Query String value using Javascript?

 var qs = (function (a) {
                if (a == "") return {};
                var b = {};
                for (var i = 0; i < a.length; ++i) {
                    var p = a[i].split('=', 2);
                    if (p.length == 1)
                        b[p[0]] = "";
                    else
                        b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
                }
                return b;
            })(window.location.search.substr(1).split('&'));


This will return the object. You can see the details using JSON.stringify(object) or access the query string property using object.propertyName

Tryit Editor

Tryit Editor
Edit This Code:
Result:



































































Wednesday, 2 September 2015

Restricting alphabets and special characters entry in a textbox using jquery

Restricting alphabets and special characters entry in a textbox and allowing only numeric value entry using jquery

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){    
$("#tbx").addClass("tbxNumber");
});
$(function () {
        $(".tbxNumber").bind("keypress", function (e) {
            var keyCode = e.which ? e.which : e.keyCode            
            var result = (keyCode >= 48 && keyCode <= 57);            
            return result;
        });
        // Restricting the Paste into textbox
        $(".tbxNumber").bind("paste", function (e) {
            return false;
        });
        // Restricting the Cut from textbox
        $(".tbxNumber").bind("cut", function (e) {
            return false;
        });
        // Restricting the Copy from textbox
        $(".tbxNumber").bind("copy", function (e) {
            return false;
        });
        // Restricting the drag and drop any value into textbox
        $(".tbxNumber").bind("drop", function (e) {
            return false;
        });        
    });
</script>

Example


<!DOCTYPE html>

<html>

<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){    
$("#tbx").addClass("tbxNumber");
});
$(function () {
        $(".tbxNumber").bind("keypress", function (e) {
            var keyCode = e.which ? e.which : e.keyCode            
            var result = (keyCode >= 48 && keyCode <= 57);            
            return result;
        });
        // Restricting the Paste into textbox
        $(".tbxNumber").bind("paste", function (e) {
            return false;
        });
        // Restricting the Cut from textbox
        $(".tbxNumber").bind("cut", function (e) {
            return false;
        });
        // Restricting the Copy from textbox
        $(".tbxNumber").bind("copy", function (e) {
            return false;
        });
        // Restricting the drag and drop any value into textbox
        $(".tbxNumber").bind("drop", function (e) {
            return false;
        });        
    });
</script>
<style>
.important {
    font-weight: bold;
    font-size: xx-large;
}

.blue {
    color: blue;
}
</style>
</head>
<body>
<h2 class="test">This is a heading</h2>
<p class="test">This is a paragraph.</p>
<p>This is another paragraph.</p>
<input type="text" class="blue important" id="tbx"></input>
</body>
</html>

Tuesday, 25 August 2015

SQL Paging

SQL Paging Select Query


SELECT *
  FROM (SELECT *
          FROM ( SELECT ROWNUM SNO
                      , RESULT.*
                   FROM (
SELECT DISTINCT PSD.PSD_SUMMARYID   PMD_SUMMARYID,
                                                  TO_CHAR(PSD.PSD_CREATEDTIME, :dateFormat) PSD_CREATEDTIME,
                                                  PSD.PSD_CREATEDTIME CREATEDTIME,
                                                  INS.INS_NAME  INSURERNAME                                             
                                               
                                    FROM [SCHEMA].PLC_PSD_PAYMENTSUMMARYDETAILS PSD
                                                INNER JOIN [SCHEMA].PLC_PMD_PAYMENTDETAILS PMD
                                                ON PSD.PSD_SUMMARYID = PMD.PMD_SUMMARYID
                                                INNER JOIN [SCHEMA].PLC_PLC_POLICY PLC
                                                ON PMD.PMD_POLICYID = PLC.PLC_POLICYID
                                                INNER JOIN [SCHEMA].MST_INS_INSURERMASTER INS
                                                ON INS.INS_INSURERID              = PSD.PSD_INSURERID
                                                WHERE PLC.PLC_APPLICATIONCLIENTKEY = :APPLICATIONCLIENTKEY
                                                AND PLC.PLC_DEALERID               = :PLC_DEALERID
                                                AND PMD.PMD_SUMMARYID IS NOT NULL
                                     order by PMD_SUMMARYID desc
) RESULT
                  WHERE ROWNUM <=(:Page_No*10) ORDER BY ROWNUM DESC )
         WHERE ROWNUM <=10 ORDER BY ROWNUM DESC
       )
 ORDER BY SNO

Thursday, 6 August 2015

pointer-events:none Chrome, IE, FireFox solved

pointer-events:none property for Chrome, IE & Firefox

This property work fine in Chrome & Firefox.
 
Alternative for Internet Explorer is given below
 
$(document).on('mousedown', '.TopElement', function (e) {
            $(this).hide();
            var BottomElement = document.elementFromPoint(e.clientX, e.clientY);
            $(this).show();
            $(BottomElement).mousedown(); //Manually fire the event for desired underlying element
            return false;
        });

Example:

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("p").click(function(){
        $(this).hide();
    });
});
$(document).on('mousedown', '#divPointer', function (e) {
            $(this).hide();
            var BottomElement = document.elementFromPoint(e.clientX, e.clientY);
            $(this).show();
            $(BottomElement).mousedown(); //Manually fire the event for desired underlying element
            return false;
        });
</script>
</head>
<body>
<p>If you click on me, I will disappear.</p>
<p>Click me away!</p>
<p>Click me too!</p>
<div id="divPointer">
<input type="text" value="umesh" style="pointer-events:none"></input></div>
</body>
</html>

Wednesday, 5 August 2015

Track changes in a HTML form (DOM onchange Event handler)

How to track changes made in a HTML form?

Description: Bind an event handler to the "change" JavaScript event, or trigger that event on an element.

This method is a shortcut for .on( "change", handler ) in the first two variations, and .trigger( "change" ) in the third.
The change event is sent to an element when its value changes. This event is limited to <input> elements, <textarea>boxes and <select> elements. For select boxes, checkboxes, and radio buttons, the event is fired immediately when the user makes a selection with the mouse, but for the other element types the event is deferred until the element loses focus.
For example, consider the HTML:
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>change demo</title>
  <style>
  div {
    color: red;
  }
  </style>
  <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
 <form>
<select name="sweets" multiple="multiple">
  <option>Chocolate</option>
  <option selected="selected">Candy</option>
  <option>Taffy</option>
  <option selected="selected">Caramel</option>
  <option>Fudge</option>
  <option>Cookie</option>
</select>
<div></div>
<div id="divChange"></div>
<input id="tb" type="text" value="umesh"></input>
  </form>
<script>
$( "form" )
  .change(function () {

    var str = "";
    $( "select option:selected" ).each(function() {
      str += $( this ).text() + " ";
    });
    $( "div" ).text( str );
$("#divChange").text($("#tb").val());
  })
  .change();
</script>
 
</body>
</html>

For more information:

Tuesday, 21 July 2015

Read and Write Object data from and to NotePad using C#

Read and Write data from and to NotePad

Is this possible by C#? Yes, this is possible by C#. Newtonsoft.Json.dll is needed for this. 

Well a ViewModel is need to be declared and data will be read or written from or to notepad as a type of this ViewModel.

Writing an Object data into a notepad

public static void WrieDataToNotePad(string filePath, Object obj)
        {
            StreamWriter writer = new StreamWriter(filePath);
            string jsonData = JsonConvert.SerializeObject(obj);
            writer.Write(jsonData);
            writer.Close();
           
        }
Example:-
NotePadInteractor.WrieDataToNotePad(AppDomain.CurrentDomain.BaseDirectory + "AppData.txt", new NotePadData { RunApp=true,ModifiedMonth=DateTime.Today.Month});

Here NotePadData is a ViewModel.

If "AppData.txt" is not available in the above location(filePath), it’ll create a file with this name in that location. Data will be stored in JSON format in the .txt file and can be used later in an application as required.

Note:- JsonConvert.SerializeObject(obj) is a part of Newtonsoft.Json.dll 

Reading an Object data from a notepad

public static NotePadData ReadNotePadData(string filePath)
        {
            try
            {
              StreamReader reader = new StreamReader(filePath);
              string jsonData = reader.ReadToEnd();
              reader.Close();
              return JsonConvert.DeserializeObject<NotePadData>(jsonData);
            }
            catch(Exception ex)
            {
                return null;
               throw ex;
            }
           
        }

If location provided in the filePath doesnot contain a file, with the given name then file not found exception will be encountered. So in order to handle this exception, codes need to be written in the catch block.

Type of ViewModel need to be given in this function JsonConvert.DeserializeObject<ViewModelName>(jsonData);

Obviously, this function is a part of Newtonsoft.Json.dll