473,397 Members | 2,084 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,397 software developers and data experts.

RegisterStartupScript and Firefox

I've got some code that uses Page.ClientScript.RegisterStartupScript to call
a javascript function from the Page_Load method in the code behind.

The code works fine in IE but the javascript function is not called at all
in Firefox. I stripped my code back to the basics and all I have now is a
webform with no controls on it and the following in the code behind:

protected void Page_Load(object sender, EventArgs e)
{
Page.ClientScript.RegisterStartupScript(typeof(Pag e),
"TestScript", "<script type='text/jscript'>alert('test script');</script>");
}

This very basic webform works in IE but not in Firefox.

I'm running .NET Framework 3.5, IE 7 and Firefox 2.0.0.11. I added
"onload="alert('onLoad')"" to the body tag to ensure that javascript was
enabled and popups were not being blocked in Firefox. The onLoad alert came
up fine but the alert added by the RegisterStartupScript did not come up.

Can anyone shed any light on this?

Cheers
Feb 13 '08 #1
4 3867
I haven't done much with RegisterStartupScript but it might be helpful to
see what the resulting HTML is, especially if you've narrowed it down to a
bare-bones page.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

"Dune88" <Du****@discussions.microsoft.comwrote in message
news:FD**********************************@microsof t.com...
I've got some code that uses Page.ClientScript.RegisterStartupScript to
call
a javascript function from the Page_Load method in the code behind.

The code works fine in IE but the javascript function is not called at all
in Firefox. I stripped my code back to the basics and all I have now is a
webform with no controls on it and the following in the code behind:

protected void Page_Load(object sender, EventArgs e)
{
Page.ClientScript.RegisterStartupScript(typeof(Pag e),
"TestScript", "<script type='text/jscript'>alert('test
script');</script>");
}

This very basic webform works in IE but not in Firefox.

I'm running .NET Framework 3.5, IE 7 and Firefox 2.0.0.11. I added
"onload="alert('onLoad')"" to the body tag to ensure that javascript was
enabled and popups were not being blocked in Firefox. The onLoad alert
came
up fine but the alert added by the RegisterStartupScript did not come up.

Can anyone shed any light on this?

Cheers
Feb 13 '08 #2
How about trying:
script type='text/javascript'

"jscript" is Microsoft - specific and the kind people at Firefox apparently
don't take kindly to it.
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com
"Dune88" wrote:
I've got some code that uses Page.ClientScript.RegisterStartupScript to call
a javascript function from the Page_Load method in the code behind.

The code works fine in IE but the javascript function is not called at all
in Firefox. I stripped my code back to the basics and all I have now is a
webform with no controls on it and the following in the code behind:

protected void Page_Load(object sender, EventArgs e)
{
Page.ClientScript.RegisterStartupScript(typeof(Pag e),
"TestScript", "<script type='text/jscript'>alert('test script');</script>");
}

This very basic webform works in IE but not in Firefox.

I'm running .NET Framework 3.5, IE 7 and Firefox 2.0.0.11. I added
"onload="alert('onLoad')"" to the body tag to ensure that javascript was
enabled and popups were not being blocked in Firefox. The onLoad alert came
up fine but the alert added by the RegisterStartupScript did not come up.

Can anyone shed any light on this?

Cheers
Feb 13 '08 #3
"Dune88" <Du****@discussions.microsoft.comwrote in message
news:FD**********************************@microsof t.com...
protected void Page_Load(object sender, EventArgs e)
{
Page.ClientScript.RegisterStartupScript(typeof(Pag e),
"TestScript", "<script type='text/jscript'>alert('test
script');</script>");
}

This very basic webform works in IE but not in Firefox.

I'm running .NET Framework 3.5, IE 7 and Firefox 2.0.0.11. I added
"onload="alert('onLoad')"" to the body tag to ensure that javascript was
enabled and popups were not being blocked in Firefox. The onLoad alert
came
up fine but the alert added by the RegisterStartupScript did not come up.

Can anyone shed any light on this?
That's because you're telling the browser that it should process a script
type of text/jscript - that will only work in IE, Opera and Safari:
http://krijnhoetmer.nl/stuff/javascript/mime-types/

If you *must* include the script tags, make sure you use
type='text/javascript', which will also work in FireFox etc...

However, it's much safer to let ASP.NET output the script tags dynamically
according to what browser it detects, by using the boolean overload of the
RegisterStartupScript method:
ClientScript.RegisterStartupScript(typeof(Page), "TestScript", "alert('test
script');", True);
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Feb 13 '08 #4
Thanks for all the replies!

Changing "jscript" to "javascript" worked perfectly as did using the boolean
overload.

Doh! I should have spotted that earlier!

"Mark Rae [MVP]" wrote:
"Dune88" <Du****@discussions.microsoft.comwrote in message
news:FD**********************************@microsof t.com...
protected void Page_Load(object sender, EventArgs e)
{
Page.ClientScript.RegisterStartupScript(typeof(Pag e),
"TestScript", "<script type='text/jscript'>alert('test
script');</script>");
}

This very basic webform works in IE but not in Firefox.

I'm running .NET Framework 3.5, IE 7 and Firefox 2.0.0.11. I added
"onload="alert('onLoad')"" to the body tag to ensure that javascript was
enabled and popups were not being blocked in Firefox. The onLoad alert
came
up fine but the alert added by the RegisterStartupScript did not come up.

Can anyone shed any light on this?

That's because you're telling the browser that it should process a script
type of text/jscript - that will only work in IE, Opera and Safari:
http://krijnhoetmer.nl/stuff/javascript/mime-types/

If you *must* include the script tags, make sure you use
type='text/javascript', which will also work in FireFox etc...

However, it's much safer to let ASP.NET output the script tags dynamically
according to what browser it detects, by using the boolean overload of the
RegisterStartupScript method:
ClientScript.RegisterStartupScript(typeof(Page), "TestScript", "alert('test
script');", True);
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Feb 13 '08 #5

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

Similar topics

6
by: Bill Jones | last post by:
I'm trying to use this.RegisterStartupScript to add some javascript to and aspx page that will run when the page is loaded. Does anyone know if this function only works in the Page_Load function? ...
11
by: Stan Sainte-Rose | last post by:
Hi, I m working on a user control. I need to use a Js file, I would like to know how to load the js file using RegisterStartupScript command from the user control. Also, if I load the same user...
0
by: rom | last post by:
my main aspx page has 3 user controls. they are all located in the same place of the page and each time i set the visibility of 2 of them to false and 1 to true. now, i want to use the...
7
by: sck10 | last post by:
Hello, I have the following sub in a class in my "App_Code" directory. The script is for setting focus on a particular control, but I get the error, "Name ClientScript Not declared". Also, I am...
9
by: C | last post by:
Hi, On a click event of a button I do some validation. If my validation is unsuccessful I display an alert to the user as below. string message = "This is a test alert.";...
2
by: Dav | last post by:
In my ASP.NET codebehind I have the following code to jump to a certain section of the page: --- Dim strAnchorScript As String = "<script language='javascript'>" & _ "window.location.hash='#" &...
3
by: MJP | last post by:
I have a button which kicks off the generation of a report after which the file will be downloaded. The report generation can take a long time, so client side onclick event of the button also...
1
by: Crazy Cat | last post by:
In the page load event of my user control I create and register a startup script with RegisterStartupScript. I am passing two controls (using the ClientID property of the controls) into a function...
3
by: Rob | last post by:
Hi, We've developed an ajax enabled web app which we're currently deploying to our production server. We use System.Web.UI.Page.RegisterStartupScript throughout the app, and all has worked well...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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...

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.