Click here to Skip to main content
15,846,004 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi ,

XML
<script type="text/javascript">
        document.onkeyup = function (e) {
            var keycode;
            if (window.event)
                keycode = window.event.keyCode;
            else if (e)
                keycode = e.which;
            if (keycode == 27) {
                if ($find("ContentPlaceHolder1_mpForHoliday")) {
                    $find("ContentPlaceHolder1_mpForHoliday").hide();
                }
            }
        }

    </script>



I am writing this script on each page for closing the modelpoups on esc key .. but is their anyway where i can get this functionlity by placing this script on single page .. such as master page and so ..
Posted

Yes just write this inside one file and save it as .js (JavaScript file), which is called External js file and include that in every page.

If you have a Master Page, then just include that External js file in that page. Automatically it will reflect in all the child pages inheriting that,
 
Share this answer
 
Comments
Torakami 24-Dec-13 0:03am    
I have created this js file

$(document).ready(function () {
document.onkeyup = function (e) {
var keycode;
if (window.event)
keycode = window.event.keyCode;
else if (e)
keycode = e.which;
if (keycode == 27) {
if ($find("ModalPopupExtender")) {
$find("ModalPopupExtender").hide();
}
}
}
});




and implemented on masterpage as suggested by you .. but not working .. is any wrong with my select stamenet
Torakami 24-Dec-13 0:24am    
I also tried with css class selector .. but still not working
Put a debugger in the code and try to check if debugger is hitting it or not.
Torakami 24-Dec-13 7:19am    
i checked that but in the if condition he is unable to track model popup and going out of scope ..problem coming on
if ($find("ModalPopupExtender")) { this line ...
That means the ID "ModalPopupExtender" is wrong.

Check the HTML in browser and try to locate the ModalPopupExtender and see what is its ID.
Use that ID.
You have to register keypress event on page load. You can place this code in master page ans add all 'ModalPopupExtenderBehaviorID' in 'if' condition.

PHP
function my_onload() {
     window.addEventListener("keypress", function (event) { myExtension_with_keypress.init(event); }, false);

     var myExtension_with_keypress = {
         init: function (event) {
             if (event.keyCode == 27) {
                 $find('ModalPopupExtenderBehaviorID').hide();
                 return false;
             }
         }
     }
 }

 window.onload = my_onload;
 
Share this answer
 
Comments
Torakami 24-Dec-13 7:12am    
But I am not using that property in any of my model popup .. will it still work
Torakami 24-Dec-13 7:16am    
And i also didnt get where to call my_onload() function
Rick Cole 24-Dec-13 7:49am    
"my_onload()" is a javascript function, So you have to use this inside the script tag.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900