Wednesday, 1 May 2013

http - How to check if a file exists on a server using VB.net

 Dim _Result As String
 Dim url
 url = dt.Rows(i)("ImageUrl").ToString()

 Dim myRequest As System.Net.HttpWebRequest = System.Net.WebRequest.Create(url)
 Dim myResponse As HttpWebResponse

   Try
    myResponse = myRequest.GetResponse()
 '_Result = myResponse.StatusCode.ToString();
    _Result = "1"
   Catch ex As System.Exception
    _Result = "0" 
   Finally
    myResponse.Close()
    myRequest = Nothing
    myResponse = Nothing
    GC.Collect()
   End Try
   Response.write(_Result)

Friday, 12 April 2013

How to use Google Maps with marker in ASP.NET, MVC

Copy-paste this code

<script type="text/javascript"  src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markermanager/src/markermanager.js"></script>


<h2>MAPS</h2>
<div id="map_canvas" style="height: 400px; width:100%;"></div>

<script language="javascript" type="text/javascript">
    var map;
    var mgr;

    function initialize() {
        var myOptions = {
            zoom: 14,
            center: new google.maps.LatLng(26.32849908419746, 73.11118125915527),
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
        mgr = new MarkerManager(map);
        var infoWindow = new google.maps.InfoWindow({ content: "SmartSign" });
        google.maps.event.addListener(mgr, 'loaded', function () {

        
                var marker = new google.maps.Marker({
                    position: new google.maps.LatLng(26.32849908419746, 73.11118125915527),
                    html: "Om Prakash Bishnoi, House No : 83, Bheru Nagar, Banaar Road, Jodhpur, Rajasthan"
                });

                google.maps.event.addListener(marker, "click", function () {
                    infoWindow.setContent(this.html);
                    infoWindow.open(map, this);
                });
                mgr.addMarker(marker, 0);
            mgr.refresh();
        });
    }
    $(document).ready(function () {
        initialize();
    });
</script>

Friday, 29 March 2013

javascript maintain page scroll position

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">
 <title>Test Page</title>
 <script type="text/javascript">
 function callTest(value)
 {
   alert(value);
 }
 </script>
</head>

<body>
 <form id="form1" runat="server">
  <table>
   <tr>
    <td style="height: 300px;">
     <a href="javascript:void(0);" id="A1" onclick="javascript:callTest('Add');" >Add</a>
     <p> Description 1............</p>
    </td>
   </tr>
   <tr>
    <td style="height: 300px;">
     <a href="javascript:void(0);" id="A2" onclick="javascript:callTest('Edit');" >Edit</a>
     <p> Description 2............</p>
    </td>
   </tr>
   <tr>
    <td style="height: 300px;">
     <a href="javascript:void(0);" id="A3" onclick="javascript:callTest('Delete');" >Delete</a>
     <p> Description 3............</p>
    </td>
   </tr>
   <tr>
    <td style="height: 300px;">
     <a href="javascript:void(0);" id="A4" onclick="javascript:callTest('View');" >View</a>
     <p> Description 4............</p>
    </td>
   </tr>
  </table>
 </form>
</body>
</html>

Get Page Name In Javascript ??

  <script type="text/javascript">

        var sPath = window.location.pathname;
       var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
       alert(sPage);

</script>

Thursday, 28 March 2013

Get Cookie Value From Javascript ??

function getCookie(cookiename)
  {
  // Get name followed by anything except a semicolon
  var cookiestring=RegExp(""+cookiename+"[^;]+").exec(document.cookie);
  // Return everything after the equal sign
  return unescape(!!cookiestring ? cookiestring.toString().replace(/^[^=]+/,"").replace("=","") : "");
  }

var myCookie = getCook('cookieName');

Saturday, 9 March 2013

how to add subTotal, grandTotal in sql query

DECLARE @t TABLE (RowNum INT IDENTITY(1,1),Grp CHAR(1), Val INT)

 INSERT INTO @t
 SELECT NULL, 1 UNION ALL
 SELECT 'A', 2 UNION ALL
 SELECT 'A', 3 UNION ALL
 SELECT 'A', 3 UNION ALL
 SELECT 'B', 4 UNION ALL
 SELECT 'A', 3 UNION ALL
 SELECT 'B', 5

 SELECT d.Grp,d.GroupTotal
   FROM (
         SELECT RowNum,
                Grp = CASE
                        WHEN GROUPING(Grp) = 0 AND GROUPING(Val) = 0 THEN Grp
                        WHEN GROUPING(Grp) = 0 AND GROUPING(Val) = 1 THEN 'Sub Total ' + ISNULL(grp,'NULL')
                        ELSE 'Grand Total'
                      END,
                GroupTotal = SUM(Val)
           FROM @t
          GROUP BY Grp,Val,RowNum WITH ROLLUP
        ) d
  WHERE RowNum > 0 OR Grp LIKE '%Total%'


Grp                  GroupTotal
NULL                   1            
Sub Total N         1            
A                          2            
A                          3            
A                          3            
A                          3            
Sub Total A         11          
B                          4            
B                          5            
Sub Total B         9            
Grand Total        21           

Friday, 1 March 2013

Write the code for selecting the 1st div, 3rd div, 3rd Last div, last div, and for even and odd div elemets ?

<div class="questions">
    <div class="myDiv"> Question</div>
    <div class="
myDiv"> Question</div>
    <div class="
myDiv"> Question</div>
    <div class="
myDiv"> Question</div>
    <div class="
myDiv"> Question</div>
    <div class="
myDiv"> Question</div>
</div>


first div : $("div.questions > div:first").css("color", "red");
3rd div : $("div.questions > div:nth-child(3)").css("color", "red");

3rd last div : $("div.questions > div::nth-last-child(3)").css 
                    ("color", "red"); 
last div : $("div.questions > div:last").css("color", "red");
even div : $("div.questions > div:even").css("color", "red");
odd div  : $("div.questions > div:odd").css("color", "red");