Click here to Skip to main content
15,885,141 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
I have a custom gridview with an export to excel feature, a column for edit/delete buttons in each row that is populated, and a footer that allows for new items to be added.

Somthing a little like this:


Showing 1-8 of 8
Results per page: 25 50 All |Export Button|
BRONCO
Edit / Delete
FLTPLAN
Edit / Delete
LASSO
Edit / Delete
PINTO
Edit / Delete
RANCH
Edit / Delete
RODEO
Edit / Delete
TEXAN
Edit / Delete
TEST
Edit / Delete
|Empty Text Box|
Add

(excuse my lazy html)

After navigating to that page a user would be able press the return key and, because it is the only button on the page, the export to excel button would be activated. I used the following Javascript to stop this:
<script type="text/javascript">
        function stopRKey(evt) { 
                  var evt = (evt) ? evt : ((event) ? event : null); 
                  var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null); 
                  if ((evt.keyCode == 13) && (node.type=="text"))  {return false;} 
                } 
                document.onkeypress = stopRKey;
            
</script>

While this is great for when the user navigates to the page, after editing an item in the gridview, the user can press enter and get the export button again. I know the script is working so I am absolutely perplexed why it's still allowing the return key after I edit/add something in the gridview.

Other (possibly) noteworthy items:
The gridview is in an update panel. Putting the javascript in the udp doesn't change anything.
The gridview is using a linq data source.
I've tried using the jscript in both the .aspx page and the master page (and both at the same time for some illogical reason).
Posted

1 solution

The cause for this is that events bubble up the document node tree with document being at the root level and the sub nodes and leaves of that tree being your HTML elements. The event will only bubble up the tree when there are no handler installed at any sub nodes of said tree. If you navigate to that page and no element having a handler for that event has the focus the event will eventually rise up to the root
document
element and be handled by you script. If you want to supress this event triggering the export button you'd have to install that handler on said button I'd say.

Best Regards,

-MRB
 
Share this answer
 
v2

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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