Javascript event triggered by ctrl x

Topics: Web Client Software Factory, User Forum
Jun 27, 2007 at 2:32 PM
I have a strange situation which is confusing me. On some of my views, when I hold ctrl x on a textbox to cut the text, it gives me a javascript bug in visual studio. It doesn't happen when I use backspace to clear out the text, only when I cut by using ctrl x. Here is the function in javascript that shows up in Visual Studio. Any help on clarifying this situation would greatly be appreciated. Thanks!

function WebForm_RemoveClassName(element, className) {
var current = element.className;
if (current) {
if (current.substring(current.length - className.length - 1, current.length) == ' ' + className) { (<----it happens here)
element.className = current.substring(0, current.length - className.length - 1);
if (current == className) {
element.className = "";
var index = current.indexOf(' ' + className + ' ');
if (index != -1) {
element.className = current.substring(0, index) + current.substring(index + className.length + 2, current.length);
if (current.substring(0, className.length) == className + ' ') {
element.className = current.substring(className.length + 1, current.length);
Jun 29, 2007 at 2:23 PM
It seems to me that your javascript function is getting called more than one time and it has a bug in certain cases where it is called after the className is already removed.

I would say the problem is "current.length - className.length - 1" might be negative in certain cases. You are not interested in the case where the current class name is less than the new one (plus the space), since that would mean the new className is not contained in the current one. Just add the check, and you will do fine.

Freddy Rios,
Jun 29, 2007 at 5:09 PM
Thanks Freddy, but the problem is, this isn't my javascript. Its generated by the code somewhere, maybe the WCSF code, or some generated code from .NET. I haven't coded this javascript anywhere so I don't know where to even look for it.
Jun 29, 2007 at 6:51 PM
As far as I know, this sounds to be related to a few known bugs regarding that ASP.NET’s javascript function, not to WCSF specifically. However, I have never heard of such behavior. Searching “WebForm_RemoveClassName” throws many results explaining how to fix them… maybe that will help to solve that issue.

Luciano G. Panaro