Pages

Monday, December 5, 2016

JQuery Autocomplete plugin


JQuery files

<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>


<input class="input ui-autocomplete-input" data-val="true" data-val-required="Please select receiver!!" id="txtboxid" maxlength="50" name="txtboxid" placeholder="enter search text" type="text" value="" autocomplete="off">

Your JQuery code

$(document).ready(function () {

    $("#txtboxid").autocomplete({
     
        source: function (request, response) {
            $.ajax({
                url: 'GetListMatchesToTheSearchText',
                type: "POST",
                dataType: "json",
                data: { searchdata: request.term },

                success: function (data) {
                    response($.map(data, function (item) {
                        return { label: item.UserName, value: item.UserName, Id: item.UserId };
                    }))
                }
            })
        },
        messages: {
            noResults: "", results: ""
        },
        select: function (event, ui) {        
            $('#labelcontrolid').val(ui.item.UserName);
        }
    });
});



Server side code to fetch the list

 public ActionResult GetStudentListMatchesToTheSearchText(string searchdata)
        {
            List<Student > ListStudent  = new List<Student>();

            ListStudent = FetchSutudentData(searchdata); // Method to fetch the student list

            return Json(ListStudent , JsonRequestBehavior.AllowGet);
        }


public class Student
(
           public int Id{get;set;}
           public string UserName{get;set;}
)




Sunday, May 8, 2016

Difference between Managed and Unmanaged code in ASP.net

Managed Code Unmanaged Code
1. Managed code is executed by the CLR, instead of Operating System. 1. Unmanaged code is executed by the Operating System directly.
2. Managed code gets the benefit of services provided by CLR like Memory Management (Garbage Collector), Thread Management, Exception handling, Type Checking etc. 2. Unmanaged code doesn't get any benefit of CLR and all things should be manage by programmer itself.
3. Code compiled by the compiler into the IL code and then again compiled by JIT to native/machine code. 3. Code compiled by the compiler into the Native/Machine code directly.
4. Ex. C#,J#,Vb.net etc. 4. Ex. Code written in C language, C++ language etc.

Thursday, December 17, 2015

each() function in Jquery - To Iterate each element over a collection

.each() function:   This function is used to iterate over the collections.
This function is same working as foreach function in asp.net.

Syntax:
 $(selector).each(callback function(){
});
Example:  Iterate over each row of a table.
$("table tr").each(function () {

     alert($(this).text());

});

You can also pass the parameters into the callback functions:
Syntax:
$(selector).each(callback function(index,element){
});
Index will give you the index of the current item.
Element will give you current element.

Example:

$(document).ready(function () {

     $("table tr").each(function (index, element) {

         alert($(element).text() + " at index: " + index);

     });


 });


Working of nested .each function:







Sunday, December 13, 2015

JQuery Selector - Select control by #Id

Selector plays a vital role in JQuery. They are used to select the control.
You can select a control by its Id, Class, tag etc.

Id Selector:

Id selector is used to select a control by its Id. We are using ’#’ in syntax.

Syntax:  $(‘#control-id’).event (…..)

<head>
    <title></title>
    <script src="Scripts/jquery-1.10.2.js"></script>
    <script type="text/javascript">
        $(document).ready(
            function () {
 $("#Button1").css("color","Red")
            });
    </script>
</head>
<body>
    <input id="Button1" type="button" value="click" />
</body>

================================================================

Id Selector returns the collection of objects, if html page has multiple controls with the same Id.

If you want to find the control is exists or not on a page you can use the length property to get the length of the collection return by id selector.

<head>
    <title></title>
    <script src="Scripts/jquery-1.10.2.js"></script>
    <script type="text/javascript">
        $(document).ready(
            function () {
                if ($('#Button2').length > 0) {
                    alert("Button2 Exists.")
                }
                else
                    alert("Button2 Not Exists.")
            });
    </script>
</head>
<body>
    <input id="Button2" type="button" value="click" />

</body>


=========================================================================================








Calculate Height and Width of a image in JQuery.


Use the JQuery inbuilt functions :


$(<image selector>).height() to calculate the height of the image.

$(<image selector>).width() to calculate the width of the image.

Here <image selector> is the selector of image, you can select the image by its tag,id, class etc.


for ex, 

you can select an image by its id (use #)
$('#imgdesert').height()

you can select an image by its class (use dot '.')

$('.myimage').height()





<script type="text/javascript">
    $(window).load(function () {
        $('#imageheightwidth').html(
            "Image height: " + $('#imgdesert').height() " <br/> Image width: " + $('#imgdesert').width()
            );
    });
</script>
<body>
    <label id="imageheightwidth" class="myimage"></label><br />
    <img id="imgdesert" src="Desert.jpg" />
</body>



Output:


Image height: 700


Image Width : 800


Notes: if you calculate the Image height & width in $(document).ready event , you will get the Image's height and width both Zero. 

Reason is $(document).ready event fires before the image fully loaded and find no image when calculate the dimensions and will show default value i.e 0











Difference between $(document).ready & $(window).load JQuery events





Understand with an example: Calculate Image height & width and display on web page.

     1.     First write code in $(document).ready() event

<script type="text/javascript">
    $(document).ready(function () {
        $('#imageheightwidth').html(
            "Image height: " + $('#imgdesert').height() + " <br/> Image width: " + $('#imgdesert').width()
            );
    });
</script>
<body>
    <label id="imageheightwidth"></label><br />
    <img id="imgdesert" src="Desert.jpg" />
</body>

Output:
Image height: 0
Image width: 0

You got the height & width zero because $(document).ready(function () fires before images fully loaded and find no image.

2. Secondly write the same code in $(window).load() event

  <script type="text/javascript">
    $(window).load(function () {
        $('#imageheightwidth').html(
            "Image height: " + $('#imgdesert').height() + " <br/> Image width: " + $('#imgdesert').width()
            );
    });
</script>


Output:
Image height: 768
Image width: 1024


Now you got the correctly calculated height and width because $(window).load(function () fires after images fully loaded and found the image when calculated.



Tuesday, September 8, 2015

OOPS Concept - OVERLOADING - a compile time Polymorphism - Early Binding - C#


OVERLOADING:



Hello friends, here i am explaining the OVERLOADING topic.. an favorite interview topic.

Few Questions that frequently ask in the interviews:

1. How do we overload a method ?
2. What is Polymorphism ?
2. What is Compile time polymorphism ?
2. What is Early Binding / Diff. between Early and late binding ?
3. What is Static and dynamic polymorphism ?   
4. Do we overload method with ref or out in signature ?           -- YES
5. Do we overload method by return type of method ?              -- NO
6. Do we overload a method by using static keyword ?              -- NO
7. Overloading is a run time or compile time polymorphism ?     -- Compile time

Polymorphism is one of the OOPS concept, Polymorphism means same name with different behaviors.

 Compile Time polymorphism OR Early Binding OR Static Polymorphism all are different names of  OVERLOADING.

Overloading is the way where you can define methods with the same name but having different functionality that's meet the definition of Polymorphism ( i.e one name many forms.)
















Wednesday, January 14, 2015

Call Server Web Method through AJAX without postback the page in ASP.Net

On CallWebMethod.aspx => 

Write a java script method to AJAX call the web method named "GetEmployeeDetails" on the server side.

  function GoForWork() {

            var userId = '<%= Session["userid"] %>';
            $.ajax({
                type: "POST",
                url: "CallWebMethod.aspx/GetEmployeeDetails",
                data: '{rid: "' + userId  + '" }',   // parameter pass in method
                contentType: "application/json; charset=utf-8",
                dataType: "json",

                success: function (response) {
                     // call on successful response
                     // get response here return from server method & create html to display data
                    }
                failure: function (response) {
                     // call on failed
                 
                    }
                }
            })
            return false;

type :   Type of method : POST,GET,DELETE..
url    :  path of the server side method, format:  {Page name}/{Method name}
data :    Send Parameters in the method
content type :  type of content in request
dataType:   type of data you sent JSON,XML etc



On CallWebMethod.aspx.cs => create a method that will call from the client side using JS and AJAX call.

  [WebMethod]
 public static string GetEmployeeDetails(string userid)
{
      DataSet ds=new DataSet();
      // fill dataset from database
      return ds.xml();
}


EXAMPLE:

        [WebMethod]
        public static enRechargeReport[] GetRechargereport(string rid)
        {
            List<enRechargeReport> lst_rechargeReport = new List<enRechargeReport>();
            try
            {
                SqlConnection _con = new SqlConnection(DB.con());
                _con.Open();
                SqlDataReader _reader = //fill data here from database

                if (_reader.HasRows)
                {
                    while (_reader.Read())
                    {
                        enRechargeReport nots = new enRechargeReport();
                        nots.Uid = Convert.ToString(_reader["UID"]);
                        nots.TransactionId = Convert.ToString(_reader["TransactionId"]);
                        nots.MSISDN = Convert.ToString(_reader["MSISDN"]);
                        nots.Amount = Convert.ToString(_reader["Amount"]);
                        nots.Service = Convert.ToString(_reader["Service"]);
                        nots.Provider = Convert.ToString(_reader["Provider"]);
                        nots.TransDate = Convert.ToString(_reader["Date"]);
                        nots.Balance = Convert.ToString(_reader["RTBalance"]);
                        nots.Status = Convert.ToString(_reader["Status"]);
                        lst_rechargeReport.Add(nots);
                    }
                }
                _reader.Close();
                _con.Close();
            }
            catch { }
            return lst_rechargeReport.ToArray();
        }


function GoForRechargeReport() {

            var a = '<%= Session["userid"] %>';
            $.ajax({
                type: "POST",
                url: "DoRecharge.aspx/GetRechargereport",
                data: '{rid: "' + a + '" }',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (response) {
                    var c = "";
                    c = c + "<table id='tab_border' class='altrowstable'><tr style='background-color: #6AA6BB;color: white'><td style='width:5px'>S. No.</td> <td>UID</td> <td>Trans. Id</td><td>Device</td><td>Provider</td><td>Service</td><td>Amount</td><td>Status</td><td>Balance</td><td>Tran. Date</td></tr></table>"
                    for (var i = 0; i < response.d.length; i++) {
                        c = c + "<table id='tbDetails' class='altrowstable'><tr><td>" + (i + 1) + "</td><td>" + response.d[i].Uid + "</td><td>" + response.d[i].TransactionId + "</td><td>" + response.d[i].MSISDN + "</td><td>" + response.d[i].Provider + "</td><td>" + response.d[i].Service + "</td><td>" + response.d[i].Amount + "</td><td>" + response.d[i].Status + "</td><td>" + response.d[i].Balance + "</td><td>" + response.d[i].TransDate + "</td></tr></table>";
                    }
                    $("panel").html(c);
                }
            })
            return false;
        }

Thursday, December 26, 2013

Write Code in aspx page - using directive - call asp.net method from design .aspx page

Add classes:

<%@ Page Language="C#" MasterPageFile="~/RT/RTMaster.master" AutoEventWireup="true"
    CodeFile="Welcome.aspx.cs" Inherits="RT_Welcome" Title="Super Recharge" %>

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>


 <div id="Div1" style="margin-bottom: 10px;">
                    <marquee direction="Horizontal" scrolldelay="130" onmouseover="this.stop()" onmouseout="this.start()">
                    <% SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ERecharge"].ConnectionString); %>
                    <% SqlDataAdapter adap = new SqlDataAdapter("Select date,news from postnews Where PostId = 'RT' Order by date desc", con); %>
                    <% DataTable dt = new DataTable(); %>
                    <% adap.Fill(dt); %>
                    <% if (dt.Rows.Count > 0) %>
                    <%{ %>
                    <% foreach(DataRow dr in dt.Rows) %>
                    <% { %>
                    <span style="color:Red; font-size:larger; font-family:Sans-Serif;"><%= dr["news"].ToString()%> (on <%= dr["date"].ToString()%>) </span>
                     <%} %>
                     <%} %></marquee>
                </div>




Saturday, November 9, 2013

Marquee Stop and Start on mouse over

<marquee height="530" direction="up" scrollamount="2" scrolldelay="2" onmouseover="this.stop()" onmouseout="this.start()" style="width: 140px">

                <p style="color:#ffffff;"><span id="ctl00_Label12">Alksldnsd sdnalsdnsad sdnasdnasldlasdn dsladnasldn<br>10/18/2013 6:22:12 PM</span>
      
     </marquee>