.NET RegisterStartupScript IE6 problem

Associate
Joined
24 Jul 2003
Posts
1,420
Location
West Mids
Just wondering if anyone has any idea on how to solve this problem I seem to be having with IE :(

I'm trying to create a client side script using RegisterStartupScript and it is writing a URL inside a <div>.

Code:
string scriptStr = "<script type=\"text/javascript\">\n";
scriptStr += "document.getElementById('fileResources').innerHTML = '<a href=\"test.html\">Testing</a>'\n";
scriptStr += "</script>";
RegisterStartupScript("startup", scriptStr);

Under FireFox, it works without any problem at all, but IE fails to display the link. However, when I tried writing in an image tag instead of a URL (just to test it), IE displayed it fine.

Maybe I'm overlooking something obvious, but it's got me stumped - any ideas? :confused:
 
It turns out that it's not the problem at all.

The div it's trying to write to is one I've made run server side since I was doing other stuff to the content server-side.

Code:
<div id="fileResources" runat="server"></div>

So it seems that IE can't write content to this div from a client-side script, where as FireFox was able to. There was no error thrown up by IE, it just wasn't rendering the output.

Looks like I'll have to change the div into something else.

Thanks for looking anyway :)

*** EDIT ***

Something very strange going on - the output has just vanished. Still not fixed yet.
 
Last edited:
Yeah, there's some underlying problem that's causing issues with the div I'm writing into.

When I find out what it is I'll post back :)
 
Now I don't know if you are doing something else and your post is just an example, but if the div is runat="server" why not just write to it in page_load?

Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        fileResources.InnerHtml = "some <a href=''>stuff</a>"
End Sub
 
You would NEVER EVER guess what was causing the problem. Just solved it!

I tried changing the location of the <div> tag and found it stopped rendering output after a certain point on the page. I eventually tracked it down to.....

an ordinary HTML anchor tag with a missing closing tag....

Code:
<a id="anchor_contentEditor" />

I changed it to:

Code:
<a id="anchor_contentEditor"></a>

I basically just put the closing tag on the end and the whole IE problem went away :D I even went back and changed it back just to see if it broke again and it did.

There's so much stuff going on in this page that I thought that if I could break down the problem and just post the problem code I was having, it would have made it easier for people to solve, but as it turns out it wasn't anything to do with it ;) *slaps self*
 
Last edited:
The one thing that just annoys me to hell is trying to get the layout to look consistent across multiple browsers. I know each browser has it's own quirks, but FireFox, Opera etc. all tend to give the same output, but IE(6) waves 2 fingers at the rest of them and decides to do its own thing.

[mini-rant]
Oh, and I really find it amazing that people STILL make sites that don't work on browsers other than IE. I was contacting my car insurer via their web site yesterday using FireFox and I was busy typing in my message...I press enter to put in a new line....and it submits the form instead. This happened before but I'd forgotten about it, so I had to break out IE just to send them a message that wasn't a wall of text..grrrrr :mad:
[/mini-rant]
 
Back
Top Bottom