7

Trying to include ThickBox (from http://jquery.com/demo/thickbox/) in an ASP.NET application.

Visual Studio is failing when I try to run the application with the error: js\ThickBox\jquery-1.2.6.min.js(11): error CS1056: Unexpected character '$'

Using Visual Studio 2008 and jquery 1.2.6

Bryce Fischer
  • 5,336
  • 9
  • 30
  • 36

4 Answers4

16

CS1056 is obviously a C# compiler error. This kind of thing happens when you put runat="server" in a client script include tag (Visual Studio attempts to compile your .js file as if it was C#). Just remove the runat="server" attribute and try again.

rciq
  • 1,309
  • 10
  • 10
4

Maybe is because of the conflict between jQuery $ and the one defined by the asp.net script library.

You can call jQuery.noConflict() then use jQuery instead of $. For example instead of $("#test") you will call jQuery("#test").

See http://docs.jquery.com/Core/jQuery.noConflict for more info.

Aleris
  • 7,981
  • 3
  • 36
  • 42
  • 1
    Never knew about that. Thanks for the answer, I fixed it by removing the runat="server" attribute of the link. Was hoping to use that to resolve the path from the master page... – Bryce Fischer Oct 14 '08 at 13:18
0

when ever we put runat="server" within script tag ,this error wil occur.

for eg:

script  type="text/javascript" id="kk" runat="server" src="js/vendor/custom.modernizr.js" 

so just remove the runat=server then this error wont come.

Lucky
  • 59
  • 1
  • 9
0

This occured for me when I was writing jQuery code in the onClick event of my asp server control.

onClientClick was surely a better option for this purpose ;)

Nurp
  • 1,409
  • 13
  • 25