I have javascript functions for shortcut keys so want to use in entire solution so i want that file in a javascript file use it in every screen so tell me how to use it.
here is my code.
javascript
<script type="text/javascript">
var isCtrl = false;
document.onkeydown = function (e) {
// alert(event.keyCode);
if (event.keyCode == 17) isCtrl = true;
if (event.keyCode == 67 && isCtrl == true) {
document.getElementById('<%= btnCreate.ClientID %>').click();
//alert("Create New");
//return false;
exit();
}
if (event.keyCode == 83 && isCtrl == true) {
document.getElementById('<%= btnSave.ClientID %>').click();
//alert("Save");
exit();
}
if (event.keyCode == 86 && isCtrl == true) {
document.getElementById('<%= btnView.ClientID %>').click();
//alert("View");
exit();
}
if (event.keyCode == 82 && isCtrl == true) {
document.getElementById('<%= btnRefresh.ClientID %>').click();
//alert("Refresh");
return false;
}
if (event.keyCode == 77 && isCtrl == true) {
document.getElementById('<%= btnShow.ClientID %>').click();
//alert("Show");
exit();
}
if (event.keyCode == 68 && isCtrl == true) {
document.getElementById('<%= btnDelete.ClientID %>').click();
//alert("Delete");
exit();
}
}
</script>
tell me how to use this with a example.
this is more of a architectural thing than anything else. If you are on ASP.NET technology i.e. be it WebForms or MVC – they all provide a concept of Master Page. As the name goes its a master view for all the other views. You can create other views by basing on the master view. The master view we usually create with the common header for the app and common footer or anything else which can be common for the site.
In your case, if you need some common javascript in all other views – the best logical place is to include the javascript in the master page. with this all other views which are based on master page will get the script automatically. use the script to include the JavaScript.
hope this helps…
Lohith (Tech Evangelist, Telerik India)