views:

68

answers:

1

I'm trying to somehow render out javascript for a particular user control rather than just having a script include for the javascript file.

The reason why I don't want a simple script include is because I need to append unique ClientID's to the dom elements at runtime.

I could hardcode the javascript in a function and just append the ClientIDs. However, this will look messy and I'm not liking the idea of hardcoding javascript code in a class- it would be a nightmare to maintain.

What are some strategies that I can use to keep javascript/markup separate from the compiled code? I want to somehow have the javascript source included in the assembly as well so that as a user control, it would not require manual script includes and have no other dependencies for it to work.

+1  A: 

I used this code from Rick Strahl's blog. Works awesome with jQuery and those types of libraries. http://www.west-wind.com/WebLog/posts/252178.aspx

HTH, ck

PS If you're using a Web Application Project you can use javascript files as embedded resources.

Hcabnettek