Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Putting same Javascript function in every ASP.net page

Reply
Thread Tools

Putting same Javascript function in every ASP.net page

 
 
Shikari Shambu
Guest
Posts: n/a
 
      08-06-2004
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


 
Reply With Quote
 
 
 
 
Juno
Guest
Posts: n/a
 
      08-06-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
 
 
 
Mark Fitzpatrick
Guest
Posts: n/a
 
      08-06-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Explorer.exe error report every time access every type of video me =?Utf-8?B?SXJ3YW5zeWFo?= ASP .Net 4 10-30-2007 07:49 AM
How to display the same links in every page? fraternitydisposal@gmail.com HTML 29 08-30-2006 10:38 PM
How to explicitly run page javascript every time the page load? Jensen bredal ASP .Net 2 10-06-2005 09:10 AM
Same variable on every JSP page Steven Java 1 03-07-2005 06:04 PM
Difference between putting code in constructor and putting code in static{} Saurabh Java 6 05-30-2004 02:44 PM



Advertisments