Override the Standard Status Bar Message of the DataGrid
page 4 of 5
by Steven Archibald
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 23408/ 90

What You Get Is What You See

Once you start the page, it should similar to the following screen capture. Your results may vary based on any CSS files linked to your page.

If you now hover the mouse cursor over the "Test this link" hyperlink, you'll see the following--pay close attention to the status bar--this is the whole point of the exercise…

Notice that the status bar shows "mouseover" as its message, which is what we coded for the mouseover event in Listing 1.

Remember, this is a standard HTML anchor element, added directly with an <a> tag. The next behavior I introduce is very important. Now just hold down the left mouse button, but do not let it up!

You'll now see the status bar change to show the following message:

Hmm! Note that in our code (Listing 1 above) we put in an override for the mousedown event. But we are seeing the value of the href parameter, not our mousedown text. What gives? Wait! It gets more interesting. Now, without letting up the left mouse button, move your cursor off the link. Hover your cursor above the link, and again press and hold the left mouse button (don't let it up yet!). All of a sudden we see something different!

Hmm! This is the actual status message that we wanted to have. So why isn't it showing up the first time? Well, the short answer is, I don't know. I do know that every other site where I have tried the same experiment provides the same behavior. My guess is there is some initialization going on with the DOM that we don't have access to (or to which I can't find documentation) that sets the mousedown status message to the value of the href parameter, and it doesn't get overridden until after the first onmousedown event is processed. So this is the big limitation in this, and apparently every, override of an anchor. If it can't be gotten around in JavaScript or HTML, it can't be gotten around in the code-behind.

So, with that limitation, play with the remainder. Hover over the standard LinkButton and see the onerous javascript message. We didn't override this one in any way, so pressing the mouse buttons doesn't change anything. Similarly, we didn't override the heading for col3 in the DataGrid. But we did override the heading link button for col1 and col2. If you hover over them, hold the left mouse button down, move the cursor away, and so on, you'll see the same behavior as the standard link. First mousedown without letting the button up gives the standard message, and subsequent mousedowns provide our intended message.

Now, finally, actually click on col1 or col2. Note that I'm not sorting in my code. But the page is performing a post back, and is returning a response regarding which action you've requested. Now examine the behavior of the link buttons again. We see the old behavior. First mousedown shows the vicious, nasty, heinous JavaScript status message. So, anytime the page loads, whether from a postback or not, this mousedown text is being set initially to the value of the href parameter. Furthermore, my JavaScript book states that the link object does not process the onmousedown event--only the onclick event. In some respects, this solution shouldn't even work, and we should be modifying the onclick event, or somehow munging the href parameter. But getting it to postback with the right control ID information would then be a complicated matter.

View Entire Article

User Comments

Title: Solution to 'Unpreventable' standard behavior   
Name: Your Daddy
Date: 2007-01-04 12:30:26 PM
The javascript "onfocus" event for the anchor element can be used to get rid of that pesky status bar message that displays when you hold the left mouse button down. In addition to using onmouseover, onmousedown, onmouseup, onmouseout, etc, add an onfocus attribute to the anchor element.


Your Daddy
Title: self.status doesn't work in Firefox   
Name: slolife
Date: 2005-10-17 7:53:59 PM
self.status='Hello' doesn't work in Firefox. Is this a security/anti phishing thing?
Title: Mr   
Name: Abdul Salam
Date: 2005-10-12 12:23:38 AM
very good Thanks
Title: Link is always visible   
Name: kraftspl
Date: 2005-09-23 6:45:18 PM
Nice work, but the referenced link is always visible in the status bar, when you click a link. You will furthermore see a status message.

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-05-29 11:45:49 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search