Monday, July 23, 2012

what is the shortcut key in eclipse? ( Eclipse Shortcuts)

Essential Shortcuts
The list of shortcuts in Eclipse is fairly long yet readily available. In fact starting with Eclipse 3.1 the full list of shortcuts can be displayed from anywhere via Ctrl+Shift+L. Nevertheless, call it information fatigue or simply a matter of style, deserving shortcuts frequently remain overlooked.
Below is a list of those shortcuts I find essential. What I mean by that is if you don't use them then you probably need additional time to execute essential everyday tasks and are not very comfortable navigating around.
So without further ado here is the list: 
Find Java Type
Start typing the name and the list gets smaller. Try typing the capital letters of the class only (e.g. type "CME" to find "ConcurrentModificationException")
Find Resource
Use this to look for XML files, text files, or files of any other type. which are in your workspace.
Open Editor Drop-Down
Presents a popup window listing currently opened files. Start typing to limit the list or simply use the down arrow key.
Quick Outline
Use this to find a method or a member variable in a class. Start typing to limit the choices. Press Ctrl+O a second time to include inherited methods.
Content Assist
Context sensitive content completion suggestions while editing Java code.
Context Information
If typing a method call with several parameters use this to show the applicable parameter types. The current parameter where the cursor is will be shown in bold.
Organize Imports
After typing a class name use this shortcut to insert an import statement. This works if multiple class names haven't been imported too.
Open Declaration
Drills down to the declaration of the type, method, or variable the cursor is on. This works much like a browser hyperlink.
Backward History
This works like a browser's Back button.
Forward History
This works like a browser's Forward button
Go to Line
Go to a specific line number.
Open Type Hierarchy
Show the type hierarchy (downward tree) or the supertype hierarchy (upward tree).

Open Call Hierarchy
Show where a method is called from. In the Call Hierarchy view keep expanding the tree to continue tracing the call chain.
Auto align the code
Select Enclosing Element
Restore Last Selection
Select Previous Element
Select Next Element
Useful for selecting context-sensitive blocks (e.g. surrounding loop, method, class, etc.)
Scroll Line Up
Scroll Line Down
Very handy if you want to scroll by 1 line without changing your cursor position or using the mouse.
Go to Previous Member
Go to Next Member
Great for stepping down through the methods of a Java source file.
Show Occurrences in File
Remove Occurrences Annotations
Use this to search within the same file - useful for occurrences of private fields and methods.
Go to Matching Bracket
Helps to find the closing bracket of lengthly if-else statements.
Incremental Find
Reverse Incremental Find
The first matching occurrence is shown with each typed letter. Press again and the next matching occurrence is shown.
Insert Line Below
Insert Line Above
Insert a line above or below the current line.
Add Block Comment
Remove Block Comment
Comment in/out blocks of code with a key stroke.
Maximize Active View or Editor
Maximize the current view or editor at the expense of all other currently shown views. Press again to restore to normal view.
Next Editor
Next View
Next Perspective
Learn these to switch among edited files, open views and perspectives.
Duplicate Lines
Copy Lines
Doesn't seem like it at first but a great shortcut once you learn to use it. Instead of select, copy and paste simply select and duplicate without affecting the clipboard.
Word Completion
This is excellent for code editing or writing plain help files with variables and other words having no English language equivalents. The word completion is based on the set of words already present in the current file.
Correct Indentation
Select a block of Java code or an entire class file and use this shortcut to correct its indentation.
Shift Tab
Remove Tab
Add Tab
Select one or more lines of code and use this shortcut to intent them further/less.
Open Search Dialog
Opens a search dialog with extensive search options for Java packages, types, methods, and fields.
Rename - Refactoring
Use this to rename type, method, or field. All existing references will be refactored as well.
Extract Local Variable
Use this to create a local variable from the selected expression. This is useful for breaking up larger expressions to avoid long lines.
Extract Method
Use this to extract a new method from existing code. The parameter list and return type will be automatically created.
Trying Out Shortcuts
A few things to keep in mind as you try the above shortcuts. If a shortcut doesn't have the described effect check if one of these is the cause of your problem:
·         Do you have an older version of Eclipse? Check the Help section to confirm the shortcut is available.
·         Is the shortcut applicable to the context (perspective) you're in? For example Ctrl+Shift+T (Open Type) is applicable in the Java perspective but not in the Resource perspective. You can find out where each shortcut is applicable by pressing Ctrl+Shift+L or by checking the Help section.
·         Is the shortcut already taken by another application? If so the other application will probably come to the foreground when you use the shortcut.
·         Is the shortcut defined twice in Eclipse? This can happen on occasion if you install additional plugins with overlapping shortcuts or more likely if you've tried to map shortcuts of your own. If there is conflict the shortcut won't work. To check this go to the Preferences or press Ctrl+Shift+L twice.

Friday, July 20, 2012

How to call .ashx file through jquery

your aspx page.
add the latest jquery into the head section

<script src="" type="text/javascript"></script>

//document ready
            type: "POST",
            url: "handler.ashx",
            data: { firstName: 'Rahul', lastName: 'Kumar' },
            // DO NOT SET CONTENT TYPE to json
            // contentType: "application/json; charset=utf-8",
            // DataType needs to stay, otherwise the response object
            // will be treated as a single string
            dataType: "json",
            success: function (response) {

your handler.ashx file

    using System;
    using System.Web;
    using Newtonsoft.Json;

    public class Handler : IHttpHandler
        public void ProcessRequest(HttpContext context)
            context.Response.ContentType = "text/plain";

            string myName = context.Request.Form["firstName"];

            // simulate Microsoft XSS protection
            var wrapper = new { d = myName };
            // in order to use JsonConvert you have to download the
            // Newtonsoft.Json dll from here

        public bool IsReusable
                return false;

Friday, June 15, 2012

Things you may not know about jQuery.

Do you have a tip nobody knows about? – Add it in the comments…
  • $.fn is just a shortcut to jQuery.prototype.
  • You can test if a jQuery collection contains any elements by trying to access the first element, e.g. if($(selector)[0]){...}.
  • jQuery normalizes the event object across all browsers! Have a look at all the available properties/methods over here:
  • When you create a plugin you have access to the jQuery chain’s previous object:
    jQuery.fn.doSomething = function() {
        this; // => $('a')
        this.prevObject; // => $('li')
        // Remember chaining in your plugins:
        return this;
    // You could even create a new 'root' plugin:
    // (Returns the 'root' of a chain)
    jQuery.fn.root = function() {
        // Root is always document so we have to 
        // go back to one before the last:
        var root = this;
        while(root.prevObject.prevObject) {
            root = root.prevObject;
        return root;
    $('li').find('a').children().root(); // <= $('li') is returned
    // Using root() is the same as using end().end() in this situation
  • You can namespace events! This is especially useful for plugin development:
    jQuery.fn.myPlugin = function() {
        // Clean up after yourself!
        jQuery.myPlugin = {
            cleanUp: function() {
                // Remove all click handlers binded
                // as a result of the plugin:
                // ALternatively, remove ALL events:
        return this.bind('click.myPlugin', function() {
            // Do something...
    // Note, you can also namespace data:
    // E.g. $(elem).data('whatever.myPlugin',value);
  • You can access all event handlers bound to an element (or any object) through jQuery’s event storage:
    // List bound events:
    console.dir( jQuery('#elem').data('events') );
    // Log ALL handlers for ALL events:
    jQuery.each($('#elem').data('events'), function(i, event){
        jQuery.each(event, function(i, handler){
            console.log( handler.toString() );
    // You can see the actual functions which will occur
    // on certain events; great for debugging!
  • jQuery natively supports JSONP (‘JSON with padding’) which effectively means you can make cross-domain "Ajax" requests (although not strictly Ajax since it doesn’t use XHR). For this to work the requested domain must have some JSONP API in place (it must be able wrap the JSON with a specified callback function). An example:
    function getLatestFlickrPics(tag,callback) {
        var flickrFeed = ''
                       + tag + '&tagmode=any&format=json&jsoncallback=?';
        jQuery.getJSON(flickrFeed, callback);
    // Usage:
    getLatestFlickrPics('ferrari', function(data){
        jQuery.each(data.items, function(i, item){
  • You might find it a little messy but jQuery enables us to create an entire DOM structure within a single chain:
    // Create and inject in one chain:
        .append('<p><a href="#">Foo</a></p>')
        .find('p a')
                // Do something...
                return false;
        .append('<p><a href="#">Bar</a></p>')
        .find('p:eq(1) a')
                // Do something else...
                return false;
  • Accessing the DOM elements within a jQuery collection is incredibly easy:
    var HTMLCollection = $('div').get();
    // Alternatively, if you only want the first element:
  • Not only can you bind events to DOM elements; you can also bind a custom event to ANY object!
    function Widget() {
        // Do something...
    var myPhotoWidget = new Widget('photos');
    jQuery(myPhotoWidget).bind('photoAdd', function() {
        // Custom event handling...
    // Trigger event:
  • Finding the index of a selected element is very easy. jQuery gives us the ‘index’ method:
    $('table tr').click(function(){
        // Find index of clicked table row:
        var index = $('table tr').index(this);
  • You can create your own filter selectors. I did a post on this a while back, but take a look at an example anyway:
    $.expr[':'].external = function(elem,index,match) {
        var url = elem.href || elem.src,
            loc = window.location;
        return !!url.match(new RegExp('^' + loc.protocol + '//' + '(?!' + loc.hostname + ')' ));
    // You can now use it within your selectors:
    // Find all external anchors:
    // Find all external script elements:
    // Determine if link is external:
    $('a#mylink').is(':external'); // true/false
  • I see quite a lot of people still using JavaScript’s FOR or WHILE constructs to create loops in their jQuery scripts. There’s nothing wrong with this but be aware that jQuery’s ‘each’ method can also iterate over arrays and objects!
    var myArr = ['apple','banana','orange'];
    $.each(myArr, function(index, item) {
        // Do something with 'item'
        // return false to BREAK
        // return true to CONTINUE
  • The ‘filter’ method accepts a String selector or a function. When using it with a function you must return false to remove the element from the stack and true to keep it:
        return this.childNodes.length > 10; // Must return a Boolean
  • You don’t have to give new elements IDs or classes to reference them later, just cache them into a variable:
    var myInjectedDiv = $('<div/>').appendTo('body');
    // Use 'myInjectedDiv' to reference the element:
    myInjectedDiv.bind('click', function(){
        // ...
  • jQuery’s ‘map’ method is incredibly useful, the passed function will be run on every item of the passed array (or object) and whatever the function returns each time is added to the new array, take a look:
    // Create an array containing all anchor HREF attributes:
    var URLs = $.map($('a'), function(elem, index){
        return elem.href;
    // URLs = ['', '', '']
  • This isn’t jQuery related but it can be very useful. When you need to compare two different ways of doing something (performance-wise) you can use the Firebug console to log the time taken to complete a chunk of code, for example:
    console.time('My first method');
    // Do something...
    console.timeEnd('My first method');
    console.time('My second method');
    // Do something else...
    console.timeEnd('My second method');
    // Firebug will log the time (in milliseconds) taken
    // to complete each chunk...

Thursday, June 14, 2012

how to write xml through datatable

write xml through datatable

StringWriter writer = new StringWriter();
        dt.WriteXml(writer, XmlWriteMode.WriteSchema, true);
        string str = writer.ToString();

Wednesday, June 13, 2012

How Set and Get ASP.NET session variables with JavaScript

Is there any possible method to directly set ASP.NET session variable with JavaScript? NO. You cannot directly set a session variable via JavaScript. But there is a work around.

In the early days of classic ASP, we achieved this by using a hidden frame and use a server post back behind the scene.

But with AJAX, we no longer need hidden frames. All you have to do is, create a new page which accepts the parameters you need to set and then call that page with necessary parameters.

var url = "AjaxCall.aspx?Userid= " + Userid; req = new ActiveXObject("Microsoft.XMLHTTP");"POST", url, true); req.send();

private void Page_Load(object sender, System.EventArgs e)
if(Request.QueryString["Userid"] != null)
Session["Userid"] =Request.QueryString["Userid"].ToString();

You can access the Session variable in your HTML page.

userid = <%=Session["Userid"]%>
Then after render it will show you the session value at the page

userid = 000912

Hope This Help..
Please leave a comment below.

Sunday, June 10, 2012

how to create polygon same like google search.

Just use the Google Map script engine...

var line;
function initialize() {
var mapDiv = document.getElementById('map-canvas');
var map = new google.maps.Map(mapDiv, {
center: new google.maps.LatLng(0, -180),
zoom: 2,
mapTypeId: google.maps.MapTypeId.ROADMAP
var path = [new google.maps.LatLng(37.772323, -122.214897),
new google.maps.LatLng(21.291982, -157.821856),
new google.maps.LatLng(-18.142599, 178.431),
new google.maps.LatLng(-27.46758, 153.027892)];

line = new google.maps.Polyline({
strokeColor: '#ff0000',
strokeOpacity: 1.0,
strokeWeight: 2


google.maps.event.addListener(map, 'click', addNewPoint);
function addNewPoint(e) {
var path = line.getPath();