dropdown list with datepicker in jquery

. Tuesday, August 30, 2011
0 comments

Hi Guys,
If you want to change drop down list values for month,day and year for chosen date from datepicket of jquery,
you can achieve this easily.

Here are the steps involve to do this

1) add the neccessary js and css files.
 in my case this was as follows :
<link rel="stylesheet" href="../../themes/base/jquery.ui.all.css">
    <script src="../../jquery-1.6.2.js"></script>
    <script src="../../ui/jquery.ui.core.js"></script>
    <script src="../../ui/jquery.ui.widget.js"></script>
    <script src="../../ui/jquery.ui.datepicker.js"></script>
    <link rel="stylesheet" href="../demos.css"> 

2) now write html for all these three drop downs in my case this was following :
  
month:
  <select id="Month">
  <option value="1">Jan</option>
  <option value="2">Feb</option>
  <option value="3">March</option>
  <option value="4">April</option>
  <option value="5">May</option>
  <option value="6">June</option>
  <option value="7">July</option>
  <option value="8">Aug</option>
  </select>

  Day:
  <select id="Day">
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
  <option value="4">4</option>
  and so on ...
  </select>

  Year:
  <select id="Year">
  <option value="2010">2010</option>
  <option value="2011">2011</option>
  <option value="2012">2012</option>
  <option value="2013">2013</option>
  <option value="2014">2014</option>
  <option value="2015">2015</option>
  <option value="2016">2016</option>
  <option value="2017">2017</option>
  </select>

3) now what we want to do is to change the value of all the three dropdowns whenever datepicket date changes to do this write the following in script section.

<script>
   $(function() {
        $( "#datepicker" ).datepicker({
            onSelect: function(dateText, inst) {
                    var startDate = new Date(dateText);
                    var selDay = startDate.getDate();
                    var selmonth=startDate.getMonth()+1;
                    var selyear=startDate.getFullYear();
                    $("#Day").val(selDay);
                    $("#Month").val(selmonth);
                    $("#Year").val(selyear);
                 }

        });
    });
</script>  

what we did here ....
first we read the selected date from datepicket and then change the selected value of all the three dropdowns accordingly so finally selected index will also changes and you will see changed date every time you change the value of datepicker.



Value Type Vs Reference Type a Simple Practical Study -c#

. Wednesday, August 24, 2011
1 comments

Hi Guys, Want to tell you today regarding some of my good experience about Value Type vs Reference Type.

Value Type :
Value Type is a memory allocation technique in which memory allocated to a separate memory block which finally get "pushed onto Stack.

Basic Example : Structure.
Type of Memory Allocation :Static

Reference Type 
Reference Type is another memory allocation technique is a memory management technique in which two things are comes into picture :
1.Stack
   used to store reference variable with its values.
2.Heap
   used to store object variable which stores the actual content.

Basic Example : Class
Type of Memory Allocation : Dynamic.

Now lets see this by an Example

1. I created one structure and one class as follows :


struct Strct
    {
        public int x, y;
    }

class Cls
    {
        public int p, q;
    }

And a Main class to call them.


 class Program
    {
        static void Main(string[] args)
        {
         
         }
   }


Now onwards I'll tell you the programming logic behind them

Scenario 1:

lets create one Instance for each of them as follows :
            Strct MainInstance = new Strct();

            Cls MainObject=new  Cls();
allocate some value for each of them as follows :
            MainInstance.x = 3;
            MainInstance.y = 4;
            MainObject.p = 3;
            MainObject.q = 4;

Now I Invoke a Test Function to check the actual situation

 Test(MainInstance,MainObject);

and This Test Function Defined as follows :


 public static void Test(ref Strct tmpstrc,ref Cls tmpcls)
        {
            tmpstrc.x = 1;
            tmpstrc.y = 2;
            tmpcls.p = 1;
            tmpcls.q = 2;
         
        }

My final code is something like this inside main


     static void Main(string[] args)
        {
            Strct MainInstance = new Strct();
            Cls MainObject=new  Cls();
            MainInstance.x = 3;
            MainInstance.y = 4;
            MainObject.p = 3;
            MainObject.q = 4;
            Test(MainInstance,MainObject);
            Console.Write("Value of Instances are {0}{1}", MainInstance.x, MainInstance.y);
            Console.Write("\n");
            Console.Write("Value of Objects are {0}{1}", MainObject.p, MainObject.q);
            Console.Read();
        }

So Guys What the Value you expect here ....

Output
Value of Instances are 3 4
Value of Objects are  1 2

B'caz Structure(Value Type) stores values separately for each variable where as Class(ReferenceType) there is allocated object reference variable which points to object of class.

so in this scenario two separate variables are created for Structure
MainInstance(3,4)
tmpstrc(1,2)

and two reference variables which references to Class
MainObject(3,4)
tmpcls(1,2)

but here we actually copied the reference of tmpcls to MainObject so this also holds the same reference now.

Scenario 2:

now I made a little bit changes inside Test function.


public static void Test(Strct tmpstrc,Cls tmpcls)
        {
              tmpcls=null;
        }


Well, what the output you expect now.

its


Value of Instances are 3 4
Value of Objects are  3 4

For Instance case its very clear b'caz each time a separate variable holds the values.
Incase of Objects this display 3 4 b'caz this time reference which is copied is null so the actual reference will works for MainObject reference variable and this will show those values which were allocated earlier.


Scenario 3: 

the last and the most important situation here occurs when we use "ref" keyword.

look at Test function Declaration
Test(ref MainInstance,ref MainObject);

and its Declaration


public static void Test(ref Strct tmpstrc,ref Cls tmpcls)
        {
            Console.Write("Copied Object{0}{1}", tmpcls.p, tmpcls.q);
            Console.Write("\n");
            Console.Write("Copied Instance{0}{1}", tmpstrc.x, tmpstrc.y);
            Console.Write("\n");
            tmpstrc.x = 1;
            tmpstrc.y = 2;
            tmpcls.p = 1;
            tmpcls.q = 2;
        }


Now What the output you expect


 Copied Object 3 4
 Copied Instance 3 4
 Value of Instances are 1 2
 Value of Objects are  1 2

In case of memory variable (Value Type) we have Interchange each values with each other.
eg: MainInstance now referes to tmpstrc and vice-versa.
In case of reference variable(Reference Type) we have Interchange their references with each other.
eg : MainObject now having reference of tmpcls and vice-versa.

but wait a minute If I set the following :
   tmpcls=null;
inside our Test Function defination then what will happend ?

This time this will executes upto displaying memory variable MainInstance but when the execution comes at
Console.Write("Value of Objects are {0}{1}", MainObject.p, MainObject.q);

this throws Null reference exception b'caz this time reference hold by MainObject(which was hold by tmpcls before sometime is null) and we are trying to display its values so this exception will be generated.

so Guys !!! Hope you enjoyed this article .catch you soon with some other stuff.










Restful urls in asp.net mvc with simple steps

. Monday, August 22, 2011
0 comments

Hi Friends,

What is REST ?
Rest is a principle followed by nowadays application architecture like MVC. its stands for representational state transfer which means
a)URL should be Identity to Operation which is Performing in Application.
b)URL should be in Human readable format so that anyone can get the idea of operation easily.

Example of Restful Urls 


Basically there are verbs associated with each operation for a particular url

eg:
I am going to explain about my practical example nowonwards which is really easy to understand.
Suppose I am Having a Controller Named Server.
Now for there could be following Scenario :

Server/ServerList   //displays List of all available servers.

Server/id/ClientList //displays List of all available clients for a particular server using its id i.e. serverid.

Server/id/DeleteServer //deletes a particular server using its id.

Server/id/DeleteClient //deletes all those clients which are associated with server for its id.

Here is how my controller is looking for all its actions with parameters,verbs they are accepting.



















Now For these action to execute we need to add views.

I used Model binding concept of Asp.net MVC to do this task and bind ServerList and ClientList with
IEnumerable<T> and AddServer/AddClient with <T>

for ServerList  Iterate through records as follows :

















same Model binding for ClientList View Page.

For AddServer Bind view with <T> as follows :

















same done for AddClient.

Benefit of doing so is you  need not to pass each parameter in function when POST is used to Create new Item,and need not to add namespace for particular model and add its fields in view,Just Iterate through ViewData.Model.

You are almost done with Rest Now Take a look into one of the great feature of MVC Architecture
Routing 
you need to specify route for above urls.

so I added the following routing in my global.asax file.


 routes.MapRoute(
           "Default", // Route name
           "Server/{id}/{action}", // URL with parameters
           new { controller = "Server",id=UrlParameter.Optional ,action = "ServerLists" } // Parameter defaults
       );

by doing so this will accepts all request for above urls.

Trick with routing : Specify More Specific Routes above Less Specific

consider a scenario : 

Suppose I am having a doubt in above urls and I added a route for AddServer,AddClient as follows :

  routes.MapRoute(
           "CustomRouteFirst", // Route name
           "Server{action}", // URL with parameters
           new { controller = "Server",action = "AddServer" } // Parameter defaults
       );
now this will match Server/AddServer and Server/AddClient but what about my other routes ?
my others urls will be treated according to this routes and consider my DeleteServer Url would be now.
Server/DeleteServer?Id=(myserverid)
which i really don't want. I need this to be Server/id/DeleteServer.

Consider another example : 

Take a look into this route first :

//[Priority]:First


routes.MapRoute(
           "SpecialRoute", // Route name
           "Category/{categorytype}", // URL with parameters
           new { controller = "Product",action = "List" } // Parameter defaults
       );

// [Priority]:Second

routes.MapRoute(
           "CustomRouteSecond", // Route name
           "{controller}/{action}/{id}", // URL with parameters
           new { controller = "Product",action = "Index",id=UrlParameter.Option } // Parameter defaults
       );


so when one request for  Category/mobilephone //this will display all mobile phone lists.
and when someone request for Product/id/Delete //in this case First route won't match and hence its comes to down for second route and transfer the state to appropriate action.

 if you swap these routes priorities  then what would be scenario.

a)for Product/id/Delete url this will go for appropriate action.
b)for Category/mobilephone this will again match with the first route(ie. generic route) and trying to go for appropriate action which is not there & hence page not found error message will appear.
Hope ! you enjoyed this article.

Connect Nokia C2-01 as USB Modem

. Wednesday, August 17, 2011
2 comments

Hi Friends, If you stuck in issue with connection Nokia C2-01 as USB Modem,I'll provide very simple steps to configure this task.

1)Download Nokia Ovi Suite 3.1.1.85
(hardware requirement displayed there is just a enclosure,just ensure that you have sufficient space in your operating system drive.)

2)After Successfull Installation,Connect Nokia C2-01 from USB Cable.
(this will detects your phone as new hardware device)

3)Before Connecting to internet please do check following things.
   a)you have set Access point in both of the side on your mobile phone and on Software on PC
     (as in my case this was bsnlnet so I used same for both of the sides.)
     i)for mobile device its inside settings->configuration->Preferred access point.
     ii)for Ovi Suite on PC its inside Tools->InternetConnection->Choose Manual and Enter AccessPoint as  
       bsnlnet
   b)leave blank for username and password,this won't required.
   
4)Connect using Connect Now Link,and enjoy 3G speed on your