tfowler
Well-known member
I am having trouble loading javascript from a file into my ASP.NET 2.0 page. If I copy the contents of the js file into my aspx page, it works. However, if I try loading it from the file called "NumericTextBoxKeyPress.js", it gives me a "A Runtime Error has occured. Do you wish to Debug? Line: 1 Error: Syntax error". Selecting yes takes me to the "NumericTextBoxKeyPress.js" file in Visual Studio, but does not highlight anything. What could be the problem?
Contents of the "NumericTextBoxKeyPress.js" file:
I try to load it in my Page.Load event like so:
Thanks for any help you can provide,
Todd
Contents of the "NumericTextBoxKeyPress.js" file:
Code:
[size=2][color=#0000ff]<[/color][/size][size=2][color=#800000]script [/color][/size][size=2][color=#ff0000]type [/color][/size][size=2][color=#0000ff]= text/javascript>[/color][/size][indent][size=2][color=#0000ff]function[/color][/size][size=2] NumericTextBoxKeyPress(sender, [/size][size=2][color=#0000ff]event[/color][/size][size=2])
[/size][size=2]{[/size]
[size=2][indent][/size][size=2][color=#0000ff]var[/color][/size][size=2] curChar = String.fromCharCode([/size][size=2][color=#0000ff]event[/color][/size][size=2].keyCode);
[/size][size=2][color=#0000ff]var[/color][/size][size=2] inpStr = sender.value + curChar;
result = inpStr.match([/size][size=2][color=#800000]^[0-9.]+$[/color][/size][size=2]);
[/size][size=2][color=#0000ff]if[/color][/size][size=2] (!result)
{[/size][indent][size=2][color=#0000ff]event[/color][/size][size=2].returnValue = [/size][size=2][color=#0000ff]false[/color][/size][size=2];
[/size][size=2][color=#0000ff]event[/color][/size][size=2].cancel = [/size][size=2][color=#0000ff]true[/color][/size][size=2];[/size]
[/indent][size=2]}[/size]
[/indent][size=2]}[/size][size=2]
[/indent][/size]</script>
I try to load it in my Page.Load event like so:
Code:
[size=2][size=2][color=#0000ff]If [/color][/size][size=2][color=#0000ff]Not [/color][/size][size=2]IsPostBack [/size][size=2][color=#0000ff]Then[/color][/size][indent][/size][size=2]ClientScript.RegisterClientScriptInclude([/size][size=2][color=#800000]"NumericTextBoxKeyPress"[/color][/size][size=2], [/size][size=2][color=#800000]"NumericTextBoxKeyPress.js"[/color][/size][size=2])[/size]
[/indent]End If
Thanks for any help you can provide,
Todd
Last edited by a moderator: