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>