Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / web / ASP.NET

Embedding Javascript in Asp.Net

2.25/5 (3 votes)
5 Jul 2011CPOL 16.2K  
This is going to do something much more interesting than merely render some HTML to the browser. This is going to inject Javascript and CSS into its containing page.
There is one main class in the ASP.NET Framework included for working with Javascript: the ClientScriptManager class. This class is exposed by the Page.ClientScript property. The ClientScriptManager class has several useful methods for working with Javascript including:


RegisterClientScriptBlock():
Adds a script to a page right after the opening server-side <form> tag

RegisterStartupScript():
Adds a script to a page right before the closing server-side <form> tag

RegisterClientScriptInclude():
Adds a reference to an external Javascript file
GetWebResourceUrl() - Returns the URL to a server-side resource

for more info: Building a Custom ASP.NET Control that uses Javascript, Cascading Style Sheets, and Ajax[^]

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)