Monday 8 February 2016

To prevent Cut, Copy and Past in ASP.NET using Jquery functions .




1.  If you don't want to alert any message then just put  below property in your control to prevent Copy, Cut and Past 

oncopy="return false"

onpaste="return false"
oncut="return false"

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




2.In JavaScript you can use below code

<script language="javascript" type="text/javascript">
     function DisableCopyPaste(e) {
         // Message to display
         var message = "Cntrl key/ Right Click Option disabled";
         // check mouse right click or Ctrl key press
         var kCode = event.keyCode || e.charCode;
         //FF and Safari use e.charCode, while IE use e.keyCode
         if (kCode == 17 || kCode == 2) {
             alert(message);
             return false;
         }
     }
</script>


 <asp:TextBox ID="txtId" runat="server" onKeyDown="return DisableCopyPaste(event)"onMouseDown="return DisableCopyPaste (event)"></asp:TextBox>


3.In JQuery you can use below code


<script lang="javascript" type="text/javascript">

         $(document).ready(function () {
             $('#<%=txt.ClientID%>').bind('copy paste cut', function (e) {
                 e.preventDefault(); //disable cut,copy,paste
                 alert('cut,copy & paste options are disabled !!');
             });
         });
       </script>

 <asp:TextBox ID="txt" runat="server"></asp:TextBox>


In the .bind(param1, param2) function first parameter you have to mention the name of property on which you want to execute function and in second parameter you write that function.



4. To check existence of substring in the string

    var str = $('#<%=txt.ClientID%>').val();
                 if (str.indexOf("Hello") >= 0) {
                     alert('Contains hello');
                 }


5. To change a string from Lower to Upper and Upper to Lower case

    var str = $('#<%=txt.ClientID%>').val();

                 alert(str.toLowerCase());

    var str = $('#<%=txt.ClientID%>').val();
                 alert(str.toUpperCase());


6. To check a numeric value 

    var str = $('#<%=txt.ClientID%>').val();

              $.isNumeric(str);

  Note- Its return boolean value.
  For numeric       - true
  For None numeric  - false





Sunday 7 February 2016

What is JQuery with a sample example ?



jQuery is a JavaScript library. It can:


  • Make your JavaScript code shorter, faster and cross browser.
  • Manipulate your HTML, like showing or hiding something from the page.
  • Handles events – it can do something when a user click a button or any other activity a user can do with a mouse.
  • Animation – for example make a part of your page fade in, fade out or just simply make something move.
  • AJAX – do a server request without refreshing your whole web page.

Code example:-


javaScript

   <script lang="javascript" type="text/javascript">
         $(document).ready(function () {
             $('#<%=Button1.ClientID%>').click(function () {

                 // this how to get text box value on button click
                 var txt = $('#<%=txt.ClientID%>').val();
                 // This how to set value to a label
                 $('#<%=lbl.ClientID%>').text(txt);
                 // This how make font bold os text
                 $('#<%=lbl.ClientID%>').css({'font-weight': 'bold', 'color':'red'});

                 $('#div1').css('background', 'yellow');
                 return false;
             });
           
         });

       </script>



HTML

     <div>   
        <Center>
        <table style="width: 60%">
            <tr>
            <td><asp:TextBox ID="txt" runat="server"></asp:TextBox></td>
            </tr>
             <tr>
             <td><asp:Label ID="lbl" runat="server" Text=""></asp:Label></td>
             </tr>
             <tr>
             <td> <asp:Button ID="Button1" runat="server" Text="Click me Now" /></td>
              </tr>
        </table>
            <div id="div1">
             <p> This is paragraph of  his might seem funny
                 because writing this jQuery tutorial
                 beginners in this blog is a little bit late.</p>

            </div>
        </Center>
    </div>



Before button click











After Entering some text and button click





















I hope its use for bignner to just undersatnd how its works.