Register javascript block globally...

C

Cliff Harris

Is there a way for me to globally add a javascript block to all pages? I
was hoping I could use one of the application events, but I don't seem to
have access to the page object to use RegisterClientScriptBlock. Is there a
way for me to accomplish this without adding something to every page?

Thanks,
-cliff
 
O

Oleg Ogurok

Extend System.Web.UI.Page class, override its Render method and register
your script there.
Then simply have every codebehind class inherit from your newly created
class.

-Oleg.
 
G

Guadala Harry

You can create your own Page class that inherits from Page (i.e., extends
Page), add RegisterStartupScript to it (plus anything else you want in all
of your pages), and then have your ASPX pages inherit from your custom Page
class.

-GH
 
G

Guadala Harry

Correction... then have your aspx.cs or aspx.vb (your code behind
classes)inherit from your new custom class.
 
C

Cliff Harris

Both your and Guadala's ideas are excellent... and that is what I would have
done had I thought of this further in advance :)
Unfortunately, I'm all done now and just want to add in the javascript, so I
was hoping to find a way to just kinda insert it in at the last minute. I'm
going to assume there is no real way to do that... so, maybe I'll get to
work on changing all my pages to inherit from my own page class (thank
goodness for Find/Replace).

Thanks,
-Cliff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top