By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,922 Members | 1,950 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,922 IT Pros & Developers. It's quick & easy.

Register javascript block globally...

P: n/a
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
Nov 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a

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.

"Cliff Harris" <he***@myrealbox.com> wrote in message
news:uV**************@TK2MSFTNGP11.phx.gbl...
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

Nov 18 '05 #2

P: n/a
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
"Cliff Harris" <he***@myrealbox.com> wrote in message
news:uV**************@TK2MSFTNGP11.phx.gbl...
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

Nov 18 '05 #3

P: n/a
Correction... then have your aspx.cs or aspx.vb (your code behind
classes)inherit from your new custom class.
"Guadala Harry" <Ch*********@gh.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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
"Cliff Harris" <he***@myrealbox.com> wrote in message
news:uV**************@TK2MSFTNGP11.phx.gbl...
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


Nov 18 '05 #4

P: n/a
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

"Oleg Ogurok" <ol**@ogurok.com.ihatespammers.ireallydo.co> wrote in message
news:10*************@corp.supernews.com...

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.

"Cliff Harris" <he***@myrealbox.com> wrote in message
news:uV**************@TK2MSFTNGP11.phx.gbl...
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


Nov 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.