473,379 Members | 1,170 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Register javascript block globally...

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
4 3040

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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: G Kannan | last post by:
Hey all! I have written a perl script to retrieve information from a HTML Form and insert the data into an Oracle database table. I am gettting the the following error message: "Use of...
2
by: thinkfr33ly | last post by:
I have a page that inserts a block of javascript dynamically into the page "Test.html". The inserted block, "Block A", then does a document.write of another script block "Block B". This script...
4
by: cotton_gear | last post by:
Hello, I need to add some javascript code block dynamically to a web page. I looked into the various postings at various groups but none seems to be solving my problem. Among the approaches...
0
by: Steve - DND | last post by:
Is it possible to somehow globally register an assembly containing custom controls so that every page doesn't need to have a <%@ Register etc... tag for the needed assembly? Thanks, Steve
3
by: Goh | last post by:
Hi, May I know how to register a java script inside the <head> tag not the body? I found only got method that able register at the body like RegisterStartupScript and RegisterClientScriptBlock....
1
by: lourivas | last post by:
Hi, I create a class with a property called MyProperty that needs to register a client script if the value is set to true. When i change the property value to true i always receive a message...
7
by: int main(void) | last post by:
Hi all, I know that register variables work fine at block scope. I tried putting a register variable in file scope, like this, #include <stdio.h> register int a = 2; int main(void) {...
3
by: dixonjm | last post by:
Hi, In my page load event i have:- RegisterClientScripts(); if (!Page.IsClientScriptBlockRegistered("BannerScript")) if (!IsPostBack) { ...
53
by: souporpower | last post by:
Hello All I am trying to activate a link using Jquery. Here is my code; <html> <head> <script type="text/javascript" src="../../resources/js/ jquery-1.2.6.js"</script> <script...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.