473,414 Members | 1,606 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,414 software developers and data experts.

Putting same Javascript function in every ASP.net page

Hi,
I have an ASP.NET website that has pages that inherit from a BasePage. I
want all pages to have some common Javascript functions.

I tried doing the following

In the Base Page
protected System.Web.UI.HtmlControls.HtmlGenericControl body;

protected void Page_Load(object sender, System.EventArgs e)

{
body.Attributes.Add("onload","javascript:alert('He llo World')");

}

And, when I access the child page MyPage.aspx I get

Object reference not set to an instance of an object.

How do I add same javascript to the body onload tag of all my pages.

TIA
Nov 18 '05 #1
2 1321
Hi,

Did you put runat=server in body tag,like <body id=Body runat=server>
or you may initiate a class before you use it,
HtmlGenericControl body = new HtmlGenericControl("body");
--
Juno
MCSD.NET, MCDBA, MCSE
----------------------------------------------------------
Support Team of EasyDotNet, INC. http://www.EasyDotNet.com
DataForm.NET - The most powerful data entry web server control for ASP.NET

"Shikari Shambu" <sh*************@hotmail.com> wrote in message
news:et**************@TK2MSFTNGP10.phx.gbl...
Hi,
I have an ASP.NET website that has pages that inherit from a BasePage. I
want all pages to have some common Javascript functions.

I tried doing the following

In the Base Page
protected System.Web.UI.HtmlControls.HtmlGenericControl body;

protected void Page_Load(object sender, System.EventArgs e)

{
body.Attributes.Add("onload","javascript:alert('He llo World')");

}

And, when I access the child page MyPage.aspx I get

Object reference not set to an instance of an object.

How do I add same javascript to the body onload tag of all my pages.

TIA

Nov 18 '05 #2
A lot of the times this happens, it's because you have the control
referenced in a class, but don't have the control defined in the actual ASPX
page. Make sure that on every page that inherits from this that the body tag
has a runat="server" attribute and you have set the id to "body". Otherwise
when it comes time to render it will have no idea where the tag is that it's
supposed to add an attribute to.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

"Shikari Shambu" <sh*************@hotmail.com> wrote in message
news:et**************@TK2MSFTNGP10.phx.gbl...
Hi,
I have an ASP.NET website that has pages that inherit from a BasePage. I
want all pages to have some common Javascript functions.

I tried doing the following

In the Base Page
protected System.Web.UI.HtmlControls.HtmlGenericControl body;

protected void Page_Load(object sender, System.EventArgs e)

{
body.Attributes.Add("onload","javascript:alert('He llo World')");

}

And, when I access the child page MyPage.aspx I get

Object reference not set to an instance of an object.

How do I add same javascript to the body onload tag of all my pages.

TIA

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Gowhera Hussain | last post by:
Use This for Learning Only .... Do Not Try To Act Smart HACKING WITH JAVASCRIPT Dr_aMado Sun, 11 Apr 2004 16:40:13 UTC This tutorial is an overview of how javascript can be used to bypass...
6
by: Andy Fish | last post by:
Hi, I want to use an anchor tag to invoke some javascript and I've read that it's bad form to use <a href="javascript:foo()"> I've read endless usenet posts and hint sites on the net, they all...
2
by: Bob P. | last post by:
Hi, basically what I'd like to do is suppress the action that causes the URL to show up in the browser status bar when I roll over a hyperlink. I know I could use the onmouseover event in each...
15
by: binnyva | last post by:
Hello Everyone, I have just compleated a JavaScript tutorial and publishing the draft(or the beta version, as I like to call it) for review. This is not open to public yet. The Tutorial is...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
8
by: Frank | last post by:
Hi, I am working with VS.NET 2005 Ultimately, I wish to call a JavaScript function from a .js file
2
by: verci | last post by:
Hi guys, sorry if this seems stupid but I'm a newbie, I'm running Windows XP Pro SP2, IE 7, VS2005, ASP.net 2.0 The problem is that I'm trying to display this news scroller made in a Javascript...
10
by: paulie | last post by:
Hi, I have been experiencing an issue when trying to use AJAX to reload a DIV area using a timer of 2000ms, which contains a html page with another DIV and javascript. Scenario -------------...
1
Frinavale
by: Frinavale | last post by:
Introduction I've seen many questions asked about how to disable the browser's back button and in the past I've replied with "it's simply not possible". It's not a good idea to disable the back...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.