Click here to Skip to main content
15,888,011 members
Articles / Web Development / ASP.NET
Tip/Trick

Embedding Javascript in Asp.Net

Rate me:
Please Sign up or sign in to vote.
2.25/5 (3 votes)
5 Jul 2011CPOL 15.5K   4
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)


Written By
Technical Lead Infostretch Ahmedabad-Gujarat
India India
Aspiring for a challenging carrier wherein I can learn, grow, expand and share my existing knowledge in meaningful and coherent way.

sunaSaRa Imdadhusen


AWARDS:

  1. 2nd Best Mobile Article of January 2015
  2. 3rd Best Web Dev Article of May 2014
  3. 2nd Best Asp.Net article of MAY 2011
  4. 1st Best Asp.Net article of SEP 2010


Read More Articles...

Comments and Discussions

 
General[My vote of 1] Not Clear at all Pin
Alireza_136228-Mar-13 20:05
Alireza_136228-Mar-13 20:05 
GeneralRe: [My vote of 1] Not Clear at all Pin
Sunasara Imdadhusen22-Apr-14 3:57
professionalSunasara Imdadhusen22-Apr-14 3:57 
GeneralReason for my vote of 2 This is too common and obvious to qu... Pin
Misha19645-Jul-11 12:39
Misha19645-Jul-11 12:39 
GeneralRe: Reason for my vote of 2This is too common and obvious to qu... Pin
Sunasara Imdadhusen22-Apr-14 3:58
professionalSunasara Imdadhusen22-Apr-14 3:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.