In this post we will discuss how we can disable right click in .aspx page in Asp.Net. We will use jQuery for this.
Also check out:
- Add Primary Key Constraint to existing table in sql server 2008
- ExecuteNonQuery(), ExecuteReader() and ExecuteScalar() in Ado.Net
- C#.Net basic interview questions and answers
Follow below steps to disable right click:
1st Step:
Give reference to the jQuery library.
Here we will give referece to jQuery library like below:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
2nd Step:
Write the jQuery function:
Below is the jQuery function that will disable right click on a page:
<script type="text/javascript" language="javascript">
$(function () {
$(this).bind("contextmenu", function () {
return false
});
});
</script>
Remember in .aspx page we have to write the above code inside the <head> </head> tag.
Also check out:
- Add Primary Key Constraint to existing table in sql server 2008
- ExecuteNonQuery(), ExecuteReader() and ExecuteScalar() in Ado.Net
- C#.Net basic interview questions and answers
Follow below steps to disable right click:
1st Step:
Give reference to the jQuery library.
Here we will give referece to jQuery library like below:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
2nd Step:
Write the jQuery function:
Below is the jQuery function that will disable right click on a page:
<script type="text/javascript" language="javascript">
$(function () {
$(this).bind("contextmenu", function () {
return false
});
});
</script>
Remember in .aspx page we have to write the above code inside the <head> </head> tag.