65.9K
CodeProject is changing. Read more.
Home

Embedding Javascript in Asp.Net

starIconstarIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIcon

2.25/5 (3 votes)

Jul 5, 2011

CPOL
viewsIcon

16182

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[^]