Pages

Friday 17 October 2014

how to prevent copy-paste of a textbox in a web application



//java script
<script type="text/javascript">
         $(document).ready(function () {
             $('#TextBox1').bind('copy paste cut', function (e) {
                 e.preventDefault(); //disable cut,copy,paste
                 alert('cut,copy & paste options are disabled !!');
             });
         });
</script>

<asp:TextBox ID="TextBox1" runat="server" oncopy="return false" onpaste="return false" oncut="return false"></asp:TextBox>

Friday 8 August 2014

autorefresh a web page after a interval

<script type="text/JavaScript">

        function AutoRefresh(t) {
            setTimeout("location.reload(true);", t);
        }
</script>

<body onload="JavaScript:AutoRefresh(1000);">

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);