Friday, March 28, 2014

Using Javascript to create a Datatime picker control in Html

hi in this post lets c how to create a datetime picker in html using Javascript.

1. download the js file using this url.

http://www.javascriptkit.com/script/script2/datetimepick.zip

2. After u download this extract the zip file and after extracting add the .js and image files into your project.

3. Below is the implementation code, you can also get the sample code in the zip file downloaded.

<!DOCTYPE html>
<html>
<head>

<script language="javascript" type="text/javascript" src="datetimepicker.js">
</script>

</head>
<body>
 
<input type="Text" id="date1" maxlength="25" size="25">

Select a Date : <a href="javascript:NewCal('date1','ddmmmyyyy',true,24)"><img src="images/cal.gif" width="20" height="18"></a>

</body>
</html>

4. Output:





Friday, March 7, 2014

Wednesday, February 19, 2014

Simple Example for ASP.NET WEB API in MVC 4 || Sample ASP.NET WEB API application

In this tutorial i will show how to develop a simple ASP.NET WEB API using MVC 4.

Asp.net Web Api is used to create http based services which can be consumed by large number of client devices or browsers or applications.

Example:

1. In Visual Studio --> go to new project --> empty mvc project

2. Right click on model and add a new class named EmployeeData.cs and define the model.

//Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MvcApplication7.Models
{
    public class EmployeeData
    {
        public int EID { get; set; }
        public string EName { get; set; }
        public int ESalary { get; set; }
    }
}

3. Now Add a new controller Name EmployeeController and select Template
 Empty API Controller.



then define the controller and run the project.

//Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using MvcApplication7.Models;

namespace MvcApplication7.Controllers
{
    public class EmployeeController : ApiController
    {
        EmployeeData[] Emp = new EmployeeData[]
         {
             new EmployeeData { EID = 1, EName = "Emp 1", ESalary = 10 },
             new EmployeeData { EID = 2, EName = "Emp 2", ESalary = 100 },
             new EmployeeData { EID = 3, EName = "Emp 3", ESalary = 1000 },
         };

        public IEnumerable<EmployeeData> GetEmployees()
        {
            return Emp;
        }
    }
}


4. In the browser it may look like this:


 so the change the url as localhost:XXXX/api/Employee 

you will get the output as given below :



Friday, January 10, 2014

examples for using try-catch-finally block in asp.net

In this post i will show how to use try-catch-finally block in asp.net.
try block has to be used accompanied my catch block or finally block or both.

1. Using  try-catch-finally block ( Finally block will be executed whether there is a exception or not )

Example :
             try
            {
                int a = 10;
                int b = 0;
                int z = a / b;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
              
            }
            finally
            {
                Console.WriteLine("Finally Block");
                Console.ReadLine();
            }



2. Using try-finally block (No Exception handled here as the catch block is removed)

Example :

          try
            {
                int a = 10;
                int b = 10;
                int z = a / b;
            }
           
            finally
            {
                Console.WriteLine("Finally Block");
                Console.ReadLine();
            }



3.  Using try-catch block

Example :

             try
            {
                int a = 10;
                int b = 0;
                int z = a / b;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.ReadLine();
            }