Friday 22 April 2016

Google Map Api Get Latitude and Longitude from Address in JavaScript

Introduction:

Here I will explain how to get latitude and longitude from address Google map api using JavaScript in website.

Description:

By giving latitude and longitude we can get exact location on google map from your website. You can get current latitude and longitude from the user and u can show thier locaion on your website using google api with javascript.

To implement places or address autocomplete textbox using Google maps Google API we need to write the code like as shown below


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Google Places Autocomplete textbox using google maps api</title>
</head>
<body>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true&libraries=places"></script>
<script type="text/javascript">
google.maps.event.addDomListener(window, 'load', initialize);
function initialize() {
var autocomplete = newgoogle.maps.places.Autocomplete(document.getElementById('txtAutocomplete'));
google.maps.event.addListener(autocomplete, 'place_changed'function () {
// Get the place details from the autocomplete object.
var place = autocomplete.getPlace();
var location = "<b>Address</b>: " + place.formatted_address + "<br/>";
location += "<b>Latitude</b>: " + place.geometry.location.A + "<br/>";
location += "<b>Longitude</b>: " + place.geometry.location.F;
document.getElementById('lblResult').innerHTML = location
});
}
</script>
<span>Location:</span>
<input type="text" id="txtAutocomplete" style="width: 300px" placeholder="Enter your address" /><br/><br />
<label id="lblResult" />
</body>
</html>

SQL Server Order By Union with Example

Introduction

Here I will explain how to use order by in union query in sql server.
  1. SELECT * FROM
  2. (
  3. Select Id as UserId, UserName as Name, RegisterDate From UserDetails
  4. Union
  5. select UserId, EmpName as Name, ModifyDate as RegisterDate From UserDetails
  6. ) smptbl
  7. ORDER BY RegisterDate DESC
If you observe above query we are getting data from union statements as sub query and applying order by statement sub query to show the data in descending order.

  1. DECLARE @temp1 table(id int, name varchar(50),modifydate date)
  2. DECLARE @temp2 table(id int, name varchar(50),modifydate date)
  3. insert into @temp1(id,name,modifydate)
  4. values(1,'Sesu,Raj','2017-01-30'),
  5. (2,'Veera,Pandiayn','2016-02-10'),
  6. (3,'Soosai,Raj','2015-03-05')
  7. insert into @temp2(id,name,modifydate)

  8. values(13,'Honey','2017-04-15'),
  9. (21,'Imman,Alavala','2016-02-05'),
  10. (21,'Jai,Ganesh','2015-01-20')
  11. SELECT * FROM (
  12. Select id,name, modifydate from @temp1
  13. UNION
  14. Select id,name, modifydate from @temp2
  15. ) stbl ORDER BY modifydate DESC

Now we will see how to use order by clause with union statements in sql server with example.

If we execute above query we will get records in modifydate descending order.

Thursday 21 April 2016

How to create sticky footer with asp.net master page?

Introduction 

Now i am going to explain how to create sticky footer with asp.net master page in simple manner.
 
Step 1
Add new visual studio project and add the necessary files like shown blow.
 
Step 2
Now open your Master Page and add this script within the head tag. 
  1. <head> 
  2. <script type="text/javascript" src="http://code.jquery.com/jquery.js"></script>  
  3.    <script type="text/javascript">  
  4.        $(window).bind("load"function () {  
  5.            var footer = $("#footer");  
  6.            var pos = footer.position();  
  7.            var height = $(window).height();  
  8.            height = height - pos.top;  
  9.            height = height - footer.height();  
  10.            if (height > 0) {  
  11.                footer.css({  
  12.                    'margin-top': height + 'px'  
  13.                });  
  14.            }  
  15.        });  
  16. </script>  
  17. </head>
 Step 3
Then write the following div within your form tag:
  1. <form id="form1" runat="server">  
  2.      
  3.  <div>  
  4.   
  5.            <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">  
  6.   
  7.            </asp:ContentPlaceHolder>  
  8.   
  9.                      <div id="footer">  
  10.                      Your Footer Content  
  11.                       </div>  
  12.   
  13.  </div>  
  14.  </form>  
Step 4
Open your aspx page (for example default.aspx). Call your master page in your aspx page.
  1. <%@ Page Title="" Language="C#" MasterPageFile="Master.Master" AutoEventWireup="true" CodeBehind="default.aspx.cs" Inherits="StickyFooter.default" %>  
Step 5
Remove all HTML elements from your default.aspx page. And add your content placeholder on your default.aspx page.
  1. <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">  
  2.   
  3. Main Content (Header Content)  
  4.   
  5. </asp:Content>  
Now you can view your footer text at the bottom.

HTML editor for asp.net web pages using JQuery instead of AJAX

Introduction
I am going to explain how to create html editor control for asp.net web pages with light weight jquery plugin. Here is the example.
 
 
Step 1 
Create new visual studio project
 
Step 2
Download files from here. Add necessary files like shown below  
  1. <script src=jquery-1.3.2.js" type="text/javascript"></script>  
  2.       
  3.     <script src="Html_editor/scripts/jHtmlArea-0.8.min.js" type="text/javascript"></script>  
  4.     <link href="Html_editor/scripts/jHtmlArea.css" rel="stylesheet" type="text/css" />  
  5.       
  6.     <script type="text/javascript">  
  7.         $(function () {  
  8.             $("textarea").htmlarea(); // Initialize jHtmlArea's with all default values
  9.         });  
  10.     </script>  
  Full Example
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SendEmail.aspx.cs" Inherits="AdventureSports.Public.SendEmail" %>  
  2.   
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  4.   
  5. <html xmlns="http://www.w3.org/1999/xhtml">  
  6. <head runat="server">  
  7.     <title></title>  
  8.  <script src="../HTML_Editor/scripts/jquery-1.3.2.js" type="text/javascript"></script>  
  9.       
  10.     <script src="../HTML_Editor/scripts/jHtmlArea-0.8.min.js" type="text/javascript"></script>  
  11.     <link href="../HTML_Editor/style/jHtmlArea.css" rel="stylesheet" type="text/css" />  
  12.       
  13.     <script type="text/javascript">  
  14.         $(function () {  
  15.             $("textarea").htmlarea(); // Initialize jHtmlArea's with all default values  
  16.   
  17.             //window.setTimeout(function() { $("form").submit(); }, 3000);  
  18.         });  
  19.     </script>  
  20. </head>  
  21. <body>  
  22.     <form id="form1" runat="server">  
  23.      <div>  
  24. <textarea runat="server" id="txtText" cols="50" rows="15"></textarea>  
  25. </div>  
  26. </form>  
  27. </body>  
  28. </html>  
This is the procedure to implement a lightweight HTML editor in your web pages in a simple manner.

Thank you!