Search This Blog

Thursday, October 18, 2012

Move elements from one list to another using jquery

This post will not help the C# gurus. Because they are already using this feature different techniques. But I hope this will be helpful for the PHP beginners :) . Now I am going to show you how you can move list items from one list box to another using simple jquery. Using jquery it is very simple than you think. :)

This is the Jquery portion:

 <script src="jquery-1.6.2.js"></script>

 <script>

 function move_forward()

 {

     //taking the selected items of list 1 and concatenating to a variable named forward_variable.

   var forward_variable='';

   $("#list1 :selected").each(function(){

       forward_variable+="<option value='"+$(this).val()+"'>"+$(this).html()+"</option>";

       $(this).remove();  

   });

     //Now appending the selected firs list's element to the list 2.

   $("#list2").append(forward_variable);

     //Sorting the list 2 so that it shows the list alphabetically

   sort_element("list2");

 }

 function move_backward()

 {

   var backward_variable='';

     //taking the selected items of list 2 and concatenating to a variable named backward_variable.

   $("#list2 :selected").each(function(){

       backward_variable+="<option value='"+$(this).val()+"'>"+$(this).html()+"</option>";

       $(this).remove();  

   });

    //Now appending the selected firs list's element to the list 1.

   $("#list1").append(backward_variable);

     //Sorting the list 2 so that it shows the list alphabetically

   sort_element("list1");

 }

 //Sorting function to sort the elements

 function sort_element(id)

 {

   var select_element = $('#'+id);

   var options_element = select_element.children('option').get();

   options_element.sort(function(a, b) {

     var compA = $(a).text().toUpperCase();

     var compB = $(b).text().toUpperCase();

     return (compA < compB) ? -1 : (compA > compB) ? 1 : 0;

   })

   $.each(options_element, function(index, items) { select_element.append(items); });

 }

 </script>


Now comes the html portion.
 <select multiple="multiple" name="list1" id="list1" style="width:200px">

   <option value="1">Ecstasy</option>  

   <option value="2">Tanjim</option>

   <option value="3">Rex</option>

   <option value="4">Artisti</option>

   <option value="5">Infinity</option>

 </select>

 <input type="button" name="forward" id="forward" onclick="move_forward()" value=">>"/>

 <input type="button" name="backward" id="backward" onclick="move_backward()" value="<<"/>

 <select multiple="multiple" name="list2" id="list2" style="width:200px">

 </select>



Simple is not it? Copy and paste the code. Run..

Tuesday, October 16, 2012

ASP.NET Interview Questions - Part 1




1.       Normally the ASP.NET interviewer starts with.....

2.       What’ is the sequence in which ASP.NET events are processed?

3.       In which event are the controls fully loaded?

4.       How can we identify that the Page is Post Back?

5.       How does ASP.NET maintain state in between subsequent request?

6.       What is event bubbling?

7.       How do we assign page specific attributes?

8.       How do we ensure viewstate is not tampered?

9.       What is the use of @ Register directives?

10.   What is the use of Smart Navigation property?

11.   What is AppSetting Section in “Web.Config” file?

12.   Where is View State information stored?

13.   What is the use of @ Output Cache directive in ASP.NET?

14.   How can we create custom controls in ASP.NET?

15.   How many types of validation controls are provided by ASP.NET?

16.   Can you explain “AutoPostBack”?

17.   How can you enable automatic paging in Data Grid?

18.   What is the use of “GLOBAL.ASAX” file?

19.   What is the difference between “Web.config” and “Machine.Config”?

20.   What is a SESSION and APPLICATION object?

21.   What is the difference between ‘Server.Transfer’ and ‘response. Redirect’ ?

22.   What is the difference between Authentication and authorization?

23.   What is impersonation in ASP.NET?

24.   Can you explain in brief how the ASP.NET authentication process works?

25.   What are the various ways of authentication techniques in ASP.NET?

26.   How does authorization work in ASP.NET?

27.   What is difference between Data grid, Datalist, and repeater?

28.   From performance point of view, how do they rate?

29.   What is the method to customize columns in Data Grid?

30.   How can we format data inside Data Grid?

31.   How to decide on the design consideration to take a Data grid, data list, or repeater?



Sunday, September 30, 2012

How to get an element whose id starts with a particular pattern

Picking an element using its id is very in jquery, is not it? But what if the situation is you have three text fields and every of their id starts with a particular pattern? For example suppose you are working with three text fields

 <input type='text' name='properties_value' id ='properties_value_1' />  
 <input type='text' name='properties_value' id ='properties_value_2' />  
 <input type='text' name='properties_value' id ='properties_value_3' />  
 <input type='button' onclick='take_all_the_input();' value='Show'/>  

Now you want to work on the every text fields value using their id's. What will do? are u planning to write code for each and every text fields like the below???

 <script>  
 function take_all_the_input()  
 {  
    var input1 = $("#properties_value_1").val();  
    var input2 = $("#properties_value_2").val();  
    var input3 = $("#properties_value_3").val();  
   // I assume you just want to alert the values  
   alert(input1+' ' +input2+' '+input3);  
 }//end of function  
 </script>  
The above code will work but that is a very novice approach and will not work if you do not know exactly how many text fields will be there. That means if you have generate the text fields dynamically in that case you cant fix the number of text fields. Now come to the solution. The better solution (I am not telling it best but better because after reading this post you may write in your blog even better solution than my solution :) ). So the better solution is go through every text field's id that starts with a particular pattern (in this case 'properties_value_') since every id has started with 'properties_value_' and work on those values.

The code will be
 <script>  
 function take_all_the_input()  
 {  
   $("input[id^='properties_value_']").each(function()  
    {  
     // I assume you just want to alert the values  
     alert($(this).val());  
    }  
 }//end of function  
 </script>  

See we have used $("input[id^='properties_value_']").each(function() {..... Here you are going to traverse each of the id that starts with 'properties_value_' How are taking the id that starts with a particular pattern? using ^= . So this will give the attributes that starts with some pattern... On the other hand the $= will help you to find the ids that ends with a particular pattern.

Hope this helps.. Happy coding.


Monday, September 24, 2012

Upgrage yourself, dont rely on what you are

You are developing your career where upgrading yourself is must. Do not just rely on PHP or .NET or Android or whatever. May be you are a very good PHP coder.  Knows so many  things but you don't know everything. But I know you will not be able to know everything. But You must have to have the eagerness to learn new things. Suppose you are very good in PHP 4. But now PHP 6 is going to reign the PHP world but still you do not want to learn even PHP 5 and as a result you are not doing OOP  just because upto PHP 4 OOP was not used that much!!! Then sorry. This is not your field. Suppose you are an advanced developer. Going to develop a chat script. But you dont have the guts to study on node.js instead you are finding a shortcut way to do it using database!!! sorry again. So just keep in mind only PHP will give nothing until you upgrade yourself.  Today you are writing duplicate codes but you are continuing it projects after projects. You should not do this. You have to have the eagerness to follow the DRY (Do not Repeat Yourself) approach. Try to attach with online group, discussion, visit popular blogs or magazines to upgrade. Now it is the time to make rounded corner using CSS3 so please dont try to do it using photoshop to make a rounded corner image.


Tuesday, September 18, 2012

Populate drop down list with XML in C#

Create XML File  named CollectionModeinSales.xml in root folder:

<?xml version="1.0" encoding="utf-8" ?>
<CollectionModes>
  <CollectionMode>
    <text>Cash</text>
    <value>Cash</value>
 
</CollectionMode>
  <CollectionMode>
    <text>Cheque</text>
    <value>Cheque</value>
  </CollectionMode>

  <CollectionMode>
    <text>D.D</text>
    <value>D.D</value>
  </CollectionMode>

  <CollectionMode>
    <text>TT</text>
    <value>TT</value>
  </CollectionMode>

  <CollectionMode>
    <text>Credit</text>
    <value>Credit</value>
  </CollectionMode>

</CollectionModes>





Add asp:DropDownList in ASPX file

 <asp:DropDownList ID="ddlCollectionType" runat="server" Width="106px">
                                                                   </asp:DropDownList>

C# Code behind file:

            DataSet dsCollectionType = new DataSet();
           
    dsCollectionType.ReadXml(AppDomain.CurrentDomain.BaseDirectory + "CollectionModeinSales.xml");
    ddlCollectionType.DataSource = dsCollectionType.Tables[0];
    ddlCollectionType.DataTextField = "text";
    ddlCollectionType.DataValueField ="value";
    ddlCollectionType.DataBind();


Monday, September 17, 2012

Understanding Session

Hi, I am here to make you understand some concepts about session. But wait.  Before that I want to tell you a story of mine. After that I will be back to the topic Session. I like to eat too much specially fast foods like burger, pizzas, fried chickens etc on the other hand I am a bit lazy also. Don't want to go to the shop . So I have kept a boy named "Sam" whose only duty is to go to my nearby shop and order them food and bring the food to me. As this is my nearby shop and I have been purchasing food from there so many times they want  to give me some discount on food. But there is a rule to get this discount. The rule is whoever goes to buy the food (me or Sam) he has to show an id of mine to the order section and also in the cash section. Based on the id the shopkeepers and cashier decides to give discount. But you know what? Sam's capability of memorizing something is very poor. When he goes to order section of the shop he can tell my id but when he goes to the cash section he forgets my id!!! In order to solve this problem what the shopkeepers are doing is at the order section when Sam is telling my Id they are keeping a note and forward it to the cash section. So now no matter whether Sam can memorize my id or not. Shop keepers are keeping the note. :)

Ok enough talking now lets come to the main point. go through the story again and replace me with client browser, request of food with requested data, my id with additional data, Shop with Server, Sam with HTTP, the note of id with session data and delivery of food as Server response :).

Me = client browser.
Request of food = Requested Data
My Id = Additional Data,
Shop = Server,
Sam = HTTP,
The note of my ID = Session Data,
Delivery of Food = Server Response.

Session is like that. When you request your server from browser using HTTP. the HTTP is a state less protocol. The page you are requesting with an additional data , that particular additional data is available to only that page. but when you goes to another page the data is lost. To make that data available also at another page, the server keeps the information of that data as session variable. Using that session variable you can have the data available at another page too just like my id is available both at order section and cash section.

Thanks for reading :). More technical terms about session will be discussed later.

Saturday, September 8, 2012

Image Preview On FileUpload Change


 Add jquery  reference in 'head' tag

jquery-1.4.3.min.js

 Add Image and FileUpload control in html :

                         <table >
                 <tr>
                    <td>
                        <span >Logo Path</span>
                    </td>
                    <td>
                        <input name="FileUpload1" id="FileUpload1" onchange="showPreview(this)" style="width:260px;" type="file">
                    </td> 
                </tr>
                       </table>
                    <div >
                      <img id="imgLogo" alt="" src="" style="width: 77px; height: 66px" />
                  </div>
 Write Javascript  Function:

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


        function showPreview(ele) {
            $('#imgLogo').attr('src', ele.value); // for IE
            if (ele.files && ele.files[0]) {
                var reader = new FileReader();
                reader.onload = function(e) {
                $('#imgLogo').attr('src', e.target.result);
                }
                reader.readAsDataURL(ele.files[0]);
            }
        }

</script>

Thursday, September 6, 2012

Define cookie path to access it everywhere in the domain

Sometimes programmers want their cookie variable available to all the pages in the domain but they don’t specify the cookie path. To make the cookie variable in all the pages in the domain one should set the cookie as below–setcookie(name of the variable,value of the cookie variable,expired time of cookie,path)the path should be “/”. If you do this way the cookie should be available all the way to the domain.
Example code : setcookie(“Name”,”Fuad”,time()+3600*24,”/”)

Monday, September 3, 2012

Jquery:ToolTip

Add New js file in the js folder named  'tltip.js'and write some code

(function($) {
    $.fn.extend({
        tltip: function(options) {
        var settings = $.extend({ delay: 300, pause: 5000, animationSpeed: 500 }, options);
            return this.each(function() {
                var control = $(this);
                var iconDirection = 'left';
                var toolTipContainer = $('<div class="tltip-container"><div class="tltip-body">' + control[0].attributes["tltitle"].nodeValue + '' +
                                        '<img   class="tltip-close"   /></div><div class="tltip-icon"></div></div>');

                control.before(toolTipContainer);
                var delay = settings.delay;
                var toolTip = toolTipContainer;
                toolTip.css({ display: 'none' }).find('div').css({ display: 'none', opacity: 0 });
                var toolTipBody = $('.tltip-body', toolTipContainer);
                var toolTipIcon = $('.tltip-icon', toolTipContainer);

                var interval;
                control.mouseover(function() {
                    var position = $(this).offset();
                    var left = position.left;
                    var top = position.top;

                    left += $(this).outerWidth();

                    toolTipBody.css('left',12);
                    toolTipIcon.css('left', 0);

                    toolTip.css({ left: left, top: top });
                    interval = setTimeout(function() {
                        showToolTip(toolTip);
                    }, delay);
                }).mouseout(function() {

                    hideToolTip(toolTip);

                }).keydown(function() {
                    clearTimeout(interval);
                });

                $('.tltip-close', toolTipContainer).click(function() {
                    hideToolTip(toolTip);
                });

                function showToolTip(toolTip) {
                    toolTip.css({ display: '' })
                    .find('div').css('display', '')
                    .stop(false, true)
                    .animate({ opacity: 1 }, settings.animationSpeed, function() {
                        setTimeout(function() {
                            hideToolTip(toolTip);
                        }, settings.pause);

                    });
                }


                function hideToolTip(toolTip) {

                    toolTip.css({ display: 'none' })
                    .find('div')
                    .stop(false, true)
                    .animate({ opacity: 0 }, settings.animationSpeed, function() {
                        $(this).css('display', 'none');
                    });
                }

            });
        }
    });
})(jQuery);


CSS:
Add new css files named 'tltip.css' and write code..

.tltip-container
{
    height: 70px;
    width: 252px;
    position: absolute;
}
.tltip-body
{
     color: White;
    font-weight: bold;
    font-family: Arial;
    font-size: 10px;
    width: 220px;
    height: 39px;
    padding: 10px;
    padding-right:20px;
    position: relative;
    float: left;
    -webkit-border-radius: 4px;
    -moz-border-radius: 4px;
    border-radius: 4px;
    behavior: url(PIE.htc);
    background-color: #D5AF1C;
}
 

.tltip-icon
{
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 6px;
    position: absolute;
    margin-top: 12px;
    border-color: transparent #D5AF1C transparent transparent;
}

.tltip-close
    {
    background:url(../images/x.png) no-repeat;
    width:25px; height:29px;
    display:inline; z-index:3200;
    position:absolute;
    top:-12px;
    right:-10px;
    cursor:pointer;
}

Add close image:

In html code:

Take reference in 'html' tag
 css/tltip.css
 js/jquery-1.4.3.min.js
 js/tltip.js


Write javascript code in html page

 <script type="text/javascript">
        $(document).ready(function () {
        $("[tltitle]").tltip();
        });
    </script>




 Add one div and three input box with new attribute named 'tltitle'

       <div id="demo">
            <input type="text" tltitle="Tooltip1." id="purple" />
            <br />
            <input type="text" tltitle="Tooltip2" id="green" />
            <br />
            <input type="text" tltitle="Tooltip3" id="yellow" />
           
        </div>



Sunday, September 2, 2012

Press Enter key and change Tab

Write  javascript code into js file named jskeypresstab.js.

$(':text').live("keypress", function(e) {
    /* ENTER PRESSED*/
    if (e.keyCode == 13) {

        /* FOCUS ELEMENT */
        var inputs = $(this).parents("form").eq(0).find(":input");
        var idx = inputs.index(this);
        if (idx == inputs.length - 1) {
            inputs[0].select()
        } else {
            inputs[idx + 1].focus(); // handles submit buttons
            inputs[idx + 1].select();
        }

        return false;
    }
});

$('select').live("keypress", function(e) {
    /* ENTER PRESSED*/
    if (e.keyCode == 13) {
        /* FOCUS ELEMENT */
        var inputs = $(this).parents("form").eq(0).find(":input");
        var idx = inputs.index(this);
        if (idx == inputs.length - 1) {
            inputs[0].select()
        } else {
            inputs[idx + 1].focus(); // handles submit buttons
            inputs[idx + 1].select();
        }

        return false;
    }
});


$('textarea').live("keypress", function (e) {
        /* ENTER PRESSED*/
        if (e.keyCode == 13) {

            /* FOCUS ELEMENT */
            var inputs = $(this).parents("form").eq(0).find(":input");
            var idx = inputs.index(this);
            if (idx == inputs.length - 1) {
                inputs[0].select();
            } else {
                inputs[idx + 1].focus(); // handles submit buttons
                inputs[idx + 1].select();
            }

            return false;
        }
    });

In html code:

Add reference in head code;

jquery-1.4.4.min.js
jskeypresstab.js

Saturday, September 1, 2012

Ajax Busy

Take new js file in your project named jsbusy.js and add javascript code into this files.

$(function() {
    $('body').append('<div id="jBusy"><p id="ajaxBusyMsg">Please wait...</p></div>');
});
//  bound to ajax start/stop document events
$(document).ajaxStart(function() {
    $('#jBusy').show();
}).ajaxStop(function() {
    $('#jBusy').hide();
});

In Html page:

Take reference into head tag:

jquery-1.4.3.min.js
jsbusy.js

CSS:

Write style into CSS file and take reference into head tag

#jBusy{
  display: none;
  margin: 0px 0px 0px -50px; /* left margin is half width of the div, to centre it */
  padding: 30px 10px 10px 10px;
  position: fixed;
  left: 50%;
  top: 40%;
  width: 200px;
  height: 100px;
  text-align: center;
  background: #e8e8e8 url(images/ajax-loader.gif) no-repeat center center;
  border: 1px solid #000
}

Add image into images folder



Thursday, August 30, 2012

Design Pattern Usefull Link

Design patterns are recurring/reusable solutions to a commonly software design problems you find again and again in real-world application development. Patterns are about design and interaction of objects, as well as providing a communication platform concerning elegant, reusable solutions to commonly encountered programming challenges.

Useful link for software design pattern is given below.....

http://www.dofactory.com/Patterns/Patterns.aspx

PHP basics


1.  In PHP 0 and FALSE are same when you will use == operator but not same when you will use === operator.=== operator checks the type and value so use === operator to check whether a function returns FALSE or not specially in case of those built in function those return FALSE in case of not finding desired result (e.g : stripos).
stripos returns FALSE if it can not find the desired needle in the haystack. so consider the following example.
//////////////////////////////
$haystack = "Basics of PHP";
$needle ="Basics";
if(stripos($haystack,$needle)==false)
echo "Match found";
///////////////////////////
This will output "Match found";
But the output should have been given if the the needle was not in the haystack. But since the needle (in this case "Basics") was in the 0 position of the haystack the stripos is returning 0. and we are using == operator . that means here false and 0 becomes same.
But if the code was like this
//////////////////////////////
$haystack = "Basics of PHP";
$needle ="Basics";
if(stripos($haystack,$needle)===false)
echo "Match found";
///////////////////////////
This will not output anything.

Wednesday, August 29, 2012

Project Management Plan(PMP)

                                                             Project Plan (Tree Structure):

1.      Project Initiation Documents
2.      Project Management
a.       Baseline
                                                                                                                                      i.      Project Management Plan
                                                                                                                                    ii.      Schedule
b.      Plan
c.       Review
3.      Requirements
a.       Baseline
                                                                                                                                      i.      Requirement Specification
                                                                                                                                    ii.      Change Requests
b.      Working
c.       Review
4.      Design
a.       Baseline
                                                                                                                                      i.      HLD
                                                                                                                                    ii.      LLD
                                                                                                                                  iii.      Class Models
b.      Working
c.       Review
5.      Source
a.       Baseline
                                                                                                                                      i.      User Interface (Forms, Report Layouts)
                                                                                                                                    ii.      Business Layer (Procedures, Functions, Triggers)
                                                                                                                                  iii.      Database Scripts (Table structures)
b.      Working
c.       Review
6.      QCT / Testing
a.       Baseline
                                                                                                                                      i.      Unit Testing
                                                                                                                                    ii.      Functional/Integration Testing
b.      Working
c.       Review
7.      Manuals
a.       Baseline
                                                                                                                                      i.      User Manual
                                                                                                                                    ii.      Operational Manual
                                                                                                                                  iii.      Technical Manual
                                                                                                                                  iv.      Training Manual
b.      Working
c.       Review