11 December 2013

Adding days to a date in C#.net

using System;
 
namespace forgetCode
{
class Program
{
static void Main(string[] args)
{
 
Console.WriteLine("Enter year in the format dd-mm-yyyy");
DateTime dt = Convert.ToDateTime(Console.ReadLine());
 
Console.WriteLine("Enter the days to add :");
int days = Convert.ToInt32(Console.ReadLine());
 
DateTime newDate = dt.AddDays(days);
Console.WriteLine(newDate.ToShortDateString());


}
 
}
}

Output: 
Enter year in the format dd-mm-yyyy 
25-12-2012 
Enter the days to add : 
7 
01-01-2013

how to open iis in windows 7 from run

  1. Click Start.
  2. In the Start Search box, type inetmgr and press ENTER.

10 December 2013

jQuery Datepicker- Disable Future Dates in Calendar

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>jQuery Datepicker: Disable Future Dates</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script>
<script type="text/javascript">
$(function() {
var date = new Date();
var currentMonth = date.getMonth();
var currentDate = date.getDate();
var currentYear = date.getFullYear();
$('#datepicker').datepicker({
maxDate: new Date(currentYear, currentMonth, currentDate)
});
});
</script>
</head>
<body>
<p>Date: <input type="text" id="datepicker" /></p>
</body>
</html>

Page Load time or Render time in javascript



how long a page loads and renders (getting of the data to the database, etc.). Id like to get the time coz ill be displaying it on the page footer using javascript so that the end user can check it.
 I was able to search this code:
<script type="text/javascript">
var from_time = new Date();
from_time = from_time.getTime();
function show_loading_time(){
var to_time = new Date();
to_time = to_time.getTime();
var secs = (to_time - from_time) /1000;
var lit = document.getElementById('footerk');
var text = lit.innerHTML;
lit.innerHTML = text + "Load Time: " + secs + " sec";
}
</script>

6 December 2013

Check for Session Timeout in Javascript and redirect to login page

  <script type="text/javascript">
        function CheckSession() {
            var session = '<%=Session["username"] != null%>';
            //session = '<%=Session["username"]%>';
            alert(session);
            if (session == false) {
                alert("Your Session has expired");
                window.location = "login.aspx";
            }
            else {
                alert(session);
            }
        }
    </script>

5 December 2013

Array, ArrayList, List and Dictionary in ASP.Net

Array, ArrayList, List and Dictionary all represent a collection of data but each are designed to satisfy differnt requirements. This article attempts to explain them with very basic examples; once you go this article I hope the next time you will feel a little more comfortable deciding what to choose and why.

Array
dataType[] myArray = new dataType[size];
  • Fixed number of array size
  • Strictly type-safe
  • Collection of elements of the same data type only
  • Elements are accessed by zero-based index
  • Array class is in the System Namespace (in other words, it is automatically available)
  • Values are assigned by assignment operator as in the following:
    int[] intArray = new int[5];
    intArray[0] = 2;
    intArray[1] = 4;
    intArray[2] = 6;
    intArray[3] = 8;
    intArray[4] = 10;
    intArray[5] = 12; //Run time errorintArray[6] = "Hello";//Compile time errorforeach (int i in intArray)
    {
        Console.WriteLine("From array " + i);
    }
        Console.WriteLine("From array " + intArray[6]); //Run time error           

ArrayList
ArrayList myArrayList = new ArrayList();
  • Size varies as required
  • Not type-safe
  • Collection of elements of the same or various data types
  • Reverse, Contains, Sort and a few other usefull methods are available that we don't get with Arrays
  • Useful when you are not sure about the size of the collection or you may need to have more than one data type in the collection
  • Elements are accessed by zero-based index
  • The data type of an ArrayList is an object type
  • Dictionary classes are in the System.Collections Namespace
  • Values are assigned by calling the Add method as in the following:
     
    ArrayList myArrayList = new ArrayList();
    myArrayList.Add(2);
    myArrayList.Add("OOPS");
    foreach (object obj in myArrayList)
    {
       Console.WriteLine("From arrayList " + obj.ToString());
    }
    Console.WriteLine("-------");

List
List<T> myList = new List<T>(); // T for data type
  • Size varies as required
  • Strictly type-safe
  • Collection of elements of the same data type only
  • Reverse, Contains, Sort and a few other useful methods are available that we don't get with Arrays
  • Useful if you want to have the features of both Array and ArrayList
  • Elements are accessed by zero-based index
  • Dictionary classes are in the System.Collections.Generic Namespace
  • Values are assigned by calling the Add method as in the following:
     
    List<int> intList = new List<int>();
    intList.Add(2);
    intList.Add(8);
    intList.Add(4);
    intList.Add(6);
    foreach (int i in intList)
    {
       Console.WriteLine("From List " + i);
    }

Dictionary
Dictionary<keyDataTypevalueDataType> myCollection = new Dictionary<keyDataTypevalueDataType>();
  • Size can vary
  • Can't have mixed data types, type-safe
  • The Collection is defined as a key-value pair
  • All of the keys must be of the same data type
  • All of the values must be of the same data type
  • Useful to deal with custom data type
  • Elements are accessed based on key
  • Dictionary classes are in the System.Collections.Generic Namespace
  • Key-Values are assigned by calling the Add method as in the following:
     Dictionary<string,Employee> Employees =new Dictionary<string,Employee>();
    Employee emp1 = new Employee("Emp01","Employee1");
    Employee emp2 = new Employee("Emp02","Employee2");
    Employee emp3 = new Employee("Emp03","Employee3");
    Employee emp4 = new Employee("Emp04","Employee4");
    Employee emp5 = new Employee("Emp05","Employee5");
    Employees.Add(emp1.empID, emp1);
    Employees.Add(emp2.empID, emp2);
    Employees.Add(emp3.empID, emp3);
    Employees.Add(emp4.empID, emp4);
    Employees.Add(emp5.empID, emp5);
    Console.WriteLine(Employees["Emp05"].getNameAndID());
    foreach (KeyValuePair<string,Employee> emp in Employees)
    {
       Console.WriteLine(emp.Key +"  >>>>>  " + emp.Value.empName);
       Console.WriteLine(emp.Value.ToString());
    }

        public class Employee
        {
            public string empID;
            public readonly string empName;
            public Employee(string empID, string name)
            {
                this.empID = empID;
                this.empName = name;
            }

        }