Hi,

I have a very strange problem with my website... I created a rather large page, consisting of a few tables with some labels and textboxes where the user can enter a mechanical car setup (it's for a racing game).

I was working with simple textboxes previously, but I recently switched over to a NumericBox control which should allow only numeric input using some client-side javascript. The NumericBox control is simply a UserControl with a single TextBox on it, and some client side events are added to this textbox which call methods from a single javascript file ("Scripts/numericValidator.js")

When I put a couple of these boxes on a page it works just fine, I can only enter numbers. For it to work though I need to add the script to the page and I do that using this line, either in the head content or in the body content controls:
asp Code:
  1. <script src="../../Scripts/numericValidator.js" type="text/javascript" />
(the path is chosen with the 'Pick URL' dialog so it should be alright, and it does indeed need to go up two directories first as the page is in the '~/Pages/RequireLogon" directory)

However, after replacing most of the textboxes on my large page with NumericBoxes, and adding this script line to my aspx code, the design view is 'broken'. I cannot see any of my controls anymore, and I cannot even put any new controls on there. It seems like the Content control is missing, even though it's still there just fine without errors in the aspx code.

When I remove the script line, the problem is fixed again, the controls re-appear. So it's definitely the script line causing the problem, but I cannot see how it could...


I tried it with a new blank page and the problem appears there too. If I use this simple page with just a button:
asp Code:
  1. <%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="Test3.aspx.vb" Inherits="F1TimeTrials.Test3" %>
  2.  
  3. <asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
  4.  
  5.     <!-- Script causes the designer to break... -->
  6.     <script src="../Scripts/numericValidator.js" type="text/javascript" />
  7.  
  8. </asp:Content>
  9. <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
  10.  
  11.     <asp:Button runat="server" Text="Button" />
  12.  
  13. </asp:Content>
then the designer is broken. I cannot see the button and I cannot add any controls either. Remove the 'script' line from the head content and it works again.

Strange...? Or am I doing something completely wrong :/



I tried restarting visual studio, deleting bin/obj folders and restarting, restarting PC, nothing helps.

Just in case it's the javascript itself causing problems I attached it so you can see it (it's not mine I found it somewhere online), but I don't think the designer will execute javascript code?!
javascript Code:
  1. // version: beta
  2. // created: 2005-08-30
  3. // updated: 2005-08-31
  4. // mredkj.com
  5. function extractNumber(obj, decimalPlaces, allowNegative)
  6. {
  7.     var temp = obj.value;
  8.    
  9.     // avoid changing things if already formatted correctly
  10.     var reg0Str = '[0-9]*';
  11.     if (decimalPlaces > 0) {
  12.         reg0Str += '\\.?[0-9]{0,' + decimalPlaces + '}';
  13.     } else if (decimalPlaces < 0) {
  14.         reg0Str += '\\.?[0-9]*';
  15.     }
  16.     reg0Str = allowNegative ? '^-?' + reg0Str : '^' + reg0Str;
  17.     reg0Str = reg0Str + '$';
  18.     var reg0 = new RegExp(reg0Str);
  19.     if (reg0.test(temp)) return true;
  20.  
  21.     // first replace all non numbers
  22.     var reg1Str = '[^0-9' + (decimalPlaces != 0 ? '.' : '') + (allowNegative ? '-' : '') + ']';
  23.     var reg1 = new RegExp(reg1Str, 'g');
  24.     temp = temp.replace(reg1, '');
  25.  
  26.     if (allowNegative) {
  27.         // replace extra negative
  28.         var hasNegative = temp.length > 0 && temp.charAt(0) == '-';
  29.         var reg2 = /-/g;
  30.         temp = temp.replace(reg2, '');
  31.         if (hasNegative) temp = '-' + temp;
  32.     }
  33.    
  34.     if (decimalPlaces != 0) {
  35.         var reg3 = /\./g;
  36.         var reg3Array = reg3.exec(temp);
  37.         if (reg3Array != null) {
  38.             // keep only first occurrence of .
  39.             //  and the number of places specified by decimalPlaces or the entire string if decimalPlaces < 0
  40.             var reg3Right = temp.substring(reg3Array.index + reg3Array[0].length);
  41.             reg3Right = reg3Right.replace(reg3, '');
  42.             reg3Right = decimalPlaces > 0 ? reg3Right.substring(0, decimalPlaces) : reg3Right;
  43.             temp = temp.substring(0,reg3Array.index) + '.' + reg3Right;
  44.         }
  45.     }
  46.    
  47.     obj.value = temp;
  48. }
  49. function blockNonNumbers(obj, e, allowDecimal, allowNegative)
  50. {
  51.     var key;
  52.     var isCtrl = false;
  53.     var keychar;
  54.     var reg;
  55.        
  56.     if(window.event) {
  57.         key = e.keyCode;
  58.         isCtrl = window.event.ctrlKey
  59.     }
  60.     else if(e.which) {
  61.         key = e.which;
  62.         isCtrl = e.ctrlKey;
  63.     }
  64.    
  65.     if (isNaN(key)) return true;
  66.    
  67.     keychar = String.fromCharCode(key);
  68.    
  69.     // check for backspace or delete, or if Ctrl was pressed
  70.     if (key == 8 || isCtrl)
  71.     {
  72.         return true;
  73.     }
  74.  
  75.     reg = /\d/;
  76.     var isFirstN = allowNegative ? keychar == '-' && obj.value.indexOf('-') == -1 : false;
  77.     var isFirstD = allowDecimal ? keychar == '.' && obj.value.indexOf('.') == -1 : false;
  78.    
  79.     return isFirstN || isFirstD || reg.test(keychar);
  80. }


Help? Thanks!