Pages

Monday, 23 June 2014

calender from date to date validator wth JQuery

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta charset="utf-8">
  <title>jQuery UI Datepicker - Default functionality</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css">
   <script>
  $(document).ready(function(){
      $("#datepicker").datepicker({
        minDate: 0,
        maxDate: "+60D",
        numberOfMonths: 2,
        onSelect: function(selected) {
            $("#Todate").datepicker("option", "minDate", selected)
        }
    });
  $("#Todate").datepicker({
        minDate: 0,
        maxDate:"+60D",
        numberOfMonths: 2,
        onSelect: function(selected) {
            $("#datepicker").datepicker("option", "maxDate", selected)
        }
    }); 
});
</script>
  <script>
      $(function () {
          $("#datepicker").datepicker();
      });
  </script>
   <script>
       $(function () {
           $("#Todate").datepicker();
       });
  </script>
</head>
<body>

<p>From Date: <input type="text" id="datepicker"></p>
 To Date :<input type="text" id="Todate"></p>

</body>
</html>

Thursday, 29 May 2014

Difference between Finalize & Dispose Method

Finalize
Dispose
Used to free unmanaged resources like files, database connections, COM etc. held by an object before that object is destroyed.
It is used to free unmanaged resources like files, database connections, COM etc. at any time.
Internally, it is called by Garbage Collector and cannot be called by user code.
Explicitly, it is called by user code and the class implementing dispose method must implement IDisposable interface.
It belongs to Object class.
It belongs to IDisposable interface.
Implement it when you have unmanaged resources in your code, and want to make sure that these resources are freed when the Garbage collection happens.
Implement this when you are writing a custom class that will be used by other users.
There is performance costs associated with Finalize method.
There is no performance costs associated with Dispose method.

Friday, 14 February 2014

Change Date-Time format in ASP .Net, C#

You can change below:
if you want replace "31/12/2005" with "12/31/2005", you can see below code:

DateTime d1 = DateTime.ToDate;
string dd = d1.Day.ToString();
string mm = d1.Month.ToString();
string yyyy = d1.Year.ToString();

string d2 = dd + "/" + mm + "/" + yyyy;

***************************************
another way :
DateTime.Today.ToString("dd-MMM-yyyy");

yourDate.toString("yyyy-MMM-dd hh:mm:ss");

DateTime.ParseExact("04/09/2013 8:09:10 PM","dd/MM/yyyy h:mm:ss tt", CultureInfo.InvariantCulture);

string result = dt.ToString("MM-dd-yyyy", CultureInfo.InvariantCulture);

Tuesday, 27 August 2013

Common regular expression in ASP .Net

Regular expression for mobile number should be start from 7 or 8 or 9
regular expression that should accept Indian mobile numbers. for example...
9788812345
9876512345
7891234567
8122212345
Syntax :
[789][0-9]{9}
Prefixing an optional (+91|0)? could make it more usable.

Regular expression for email , should be taking only numeric domain name like:

abc133@jhjh.dfsd : True
456@jhj.hh : True
8678@656.687 : False
hgh@679.vhhv : False
hgh@jbnj.656 : False

Syntax :
"^([0-9a-zA-Z]+[-._+&amp;])*[0-9a-zA-Z]+@([-a-zA-Z]+[.])+[a-zA-Z]{2,6}$"

Wednesday, 21 August 2013

One-liner if statements, how to convert this if-else-statement

Syntax :
return (expression) ? value1 : value2;
If value1 and value2 are actually true and false like in your example, you may as well just

return expression;
or
<result> = <condition> ? <true result> : <false result>;
Example :
string result = 5 > 10 ? "5 is greater than 10." : "5 is not greater than 10.";