Geeks With Blogs
No Fun Intended Shoo! You are debugging the crap outta me!

I had a bit of trouble figuring this one out. I needed to include a script in a MasterPage dynamically based on the url/path of the current page. Eventually, I found the ClientScriptManager.RegisterClientScriptInclude method. Here is a short snippet:

if (Request.RawUrl.ToLower().IndexOf("/client") > 0)
{
     cs.RegisterClientScriptInclude(
"ClientScripts", "../../Scripts/ClientScripts.js");
}
else if (Request.RawUrl.ToLower().IndexOf("/contacts") > 0)
{
     cs.RegisterClientScriptInclude(
"ContactScripts", "../../Scripts/ContactScripts.js");
}

That is all well and good but ClientScriptManager is the real jewel here. Anyone that has had to manage client scripts in ASP.NET 1.x knows what a pain it is and the ClientScriptManager makes it so easy. I can count at least a dozen instances it would have been gold to have it with 1.x.

Posted on Monday, October 31, 2005 3:55 AM .NET | Back to top


Comments on this post: MasterPages Dynamic Script Include

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Jason Bentley | Powered by: GeeksWithBlogs.net