Share Blog

Saturday, May 31, 2014

Disable Copy/Paste/Right Click using Javascript in ASP.NET TextBox

Description:-

In this Example we Explain that How to DISABLE Cut,copy,Paste option in TextBox or Disabled CTRL+C, CTRL+V and CTRL+X. in TextBox using Javascript
Due to some reasons or in many situation like don’t allow to copy Password from Password TextBox to Confirm Password TextBox or Copy Password from TextBox to Confirm Password TextBox as we all see in every web application so we restrict users to copy, paste and cut contents from TextBox by using CTRL+C, CTRL+V and CTRL+X. We can implement this functionality by using below methods.


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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
      <title>Disable Copy/Paste/Right Click using Javascript in ASP.NET TextBox</title>

    <script type="javascript">

        function DisableRightClick(event) {

            //For mouse right click

            if (event.button == 2) {

                alert("Right Click is Disabled....!");

            }

        }

        function DisableCtrlKey(e) {

            var code = (document.all) ? event.keyCode : e.which;

            var message = "Ctrl key  is disabled.......!";

            // look for CTRL key press

            if (parseInt(code) == 3) {

                alert(message);

                window.event.returnValue = false;

            }

        }

    </script>

  
    <style type="text/css">
        .auto-style1
        {
            width: 100%;
        }
        .auto-style2
        {
            width: 162px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
        <table class="auto-style1">
            <tr>
                <td class="auto-style2">
                    <asp:Label ID="Label1" runat="server" Text="User Name"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="TextBox1" runat="server" onmousedown="DisableRightClick(event)"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="auto-style2">
                    <asp:Label ID="Label2" runat="server" Text="Password"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="TextBox2" runat="server" onkeydown="return DisableCtrlKey(event) "></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="auto-style2">
                    <asp:Label ID="Label3" runat="server" Text="Confirm Password"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="TextBox3" runat="server" oncopy="return false" onpaste="return false" oncut="return false"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="auto-style2">
                    <asp:Button ID="Button1" runat="server" Text="Login" />
                </td>
                <td>&nbsp;</td>
            </tr>
        </table>
   
    </div>
    </form>
</body>

</html>


Using JQuery  -------------

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

Thursday, May 29, 2014

Sql Server Interview Questions and Answers

1.) What is Data Integrity in sql server?                                                                              


The Consistency of data is known as data Integrity.If Data integrity concepts is applied on table then data will become in consistence form.Means we can easily access a specific value from table easily.

2.) What types of data integrity concepts are used in sql sever?                               

  • Entity Integrity
  • Referential Integrity
  • Domain Integrity
3.) How can create primary key constraints on a table's column in
 sql server ?  

create table student(id int constraint pk_id primary key,name varchar(50),age int)


4.) How can add primary key constraints on a Existing table in
 sql server ?         
Before Creating Primary key on a table.First make table not null able as given below:

alter table student alter column id int not null


Now create constraints on existing table's column:- 

alter table student add primary key (id).


5.) How to check whether constraints are present in table or not  ?                         
sp_help constraint student

6.) What is Referential Integrity in Sql server  ?                                                                
If a table column refer to another table column, then both column(parent, child) have same value as specify within parent column.we can't delete parent table if child table is exist in database.
here my two tables are:-

  • Student
  • Scourse

Example:-
alter table cource add constraint fk_id foreign key(id) references student(id)

7.) How can fetch the multiple table values in  Sql server  ?                                         
select *from student,course

8.) How can delete the a constraint from table in  Sql server  ?                                    
alter table cource drop constraint fk_sid

9.) What is Domain Integrity in  Sql server  ?                                                                       
Domain Intigrity insures that values within the column should be according to the "Business logic" (within specify range).To implement this integrity we can specify the 'Check constraint' and 'Default constraint'.

10.) How to create constraints at column level  on a table ?                                         
create table student(id int primary key,name varchar(50),age int)

11.) How to create constraints at table level  in sql server?                                           
Create table student (id int, sname varchar(50),age int,constraint id primary key( id,name,age))

Difference between LINQ to SQL and Entity Framework

LINQ to SQL allow you to query and modify SQL Server database by using LINQ syntax. Entity framework is a great ORM shipped by Microsoft which allow you to query and modify RDBMS like SQL Server, Oracle, DB2 and MySQL etc. by using LINQ syntax. Today, EF is widely used by each and every .NET application to query to database. The difference between LINQ to SQL and EF is given below.

LINQ to SQL
Entity Framework
It only works with SQL Server Database.
It can works with various databases like Oracle, DB2, MYSQL, SQL Server etc.
It generates a .dbml to maintain the relation
It generates an .edmx files initially. The relation is maintained using 3 different files .csdl, .msl and .ssdl
It has not support for complex type.
It has support for complex type.
It cannot generate database from model.
It can generate database from model.
It allows only one to one mapping between the entity classes and the relational tables /views.
It allows one-to-one, one-to-many & many-to-many mappings between the Entity classes and the relational tables /views
It allows you to query data using DataContext.
It allows you to query data using EntitySQL, ObjectContext, DbContext.
It provides a tightly coupled approach.
It provides a loosely coupled approach. Since its code first approach allow you to use Dependency Injection pattern which make it loosely coupled .
It can be used for rapid application development only with SQL Server.
It can be used for rapid application development with RDBMS like SQL Server, Oracle, DB2 and MySQL etc.