From: Cal Who on

"Registered User" <n4jvp(a)ix.netcom.com> wrote in message
news:42qhv51mlka86p7547o6qo2j48nfmcf78t(a)4ax.com...
> On Sat, 22 May 2010 20:34:51 -0400, " Cal Who"
> <CalWhoNOSPAM(a)roadrunner.com> wrote:
>
>>
>>"Registered User" <n4jvp(a)ix.netcom.com> wrote in message
>>news:rbogv5p4i6uotm8qgsr8ajok5b1jhvdd4s(a)4ax.com...
>>> On Sat, 22 May 2010 18:19:25 -0400, " Cal Who"
>>> <CalWhoNOSPAM(a)roadrunner.com> wrote:
>>>
>>>>That's what I thought but lost confidence when it returned null in the
>>>>following:
>>>>
>>>><script type="text/javascript">
>>>>
>>>>function SetMargins(id) {
>>>>
>>>>var element = document.getElementById(id);
>>>>
>>>>...
>>>>
>>>>Which is in the .master and the id looks like I'd expect:
>>>>
>>>>id = "ctl00_BottomImageCPH_QQQ"
>>>>
>>>>
>>>>
>>>>I called it from and aspx.vb file
>>>>
>>>><asp:Content ID="Content8" runat="server"
>>>>ContentPlaceHolderID="BottomImageCPH">
>>>>
>>>><script type="text/javascript">
>>>>
>>>>SetMargins('<%=QQQ.ClientID%>');
>>>>
>>>></script>
>>>>
>>>>
>>>><div runat="server" id="QQQ" style="margin-left: 10%; margin-right:
>>>>10%;"
>>>> >
>>>>
>>>>...
>>>>
>>>>
>>>>Why the null??
>>>>
>>> From the second snippet it appears the SetMargins method is being
>>> called as the document is rendered. The document is rendered from top
>>> to bottom. If SetMargins is called before control QQQ is rendered to
>>> the document, the document won't find the control, and
>>> document.getElementById will return null.
>>I bet that is why IE8 developer tool only shows the HTML to just befor
>>QQQ.
>>That's as much as was rendered.
>>
>>
>>>
>>> You may have to read that last sentence a couple of times ;)
>>>
>>> I would suggest attaching a javascript method to the page body's
>>> onload event. That method will be called after the page has been
>>> rendered. From within that method make the call to SetMargins.
>>
>>But there are no events in a content page, is there?
>>
> This is true but a solution can be found at
> http://www.webreference.com/programming/javascript/onloads/
>
> regards
> A.G.

I moved the call to right after the </div> and that seems to have fixed it.
I'm not sure if that is a reliable way.

Do you think adding an event would be more reliable (say over different
browser types)

In this situation I don't see the "magically change" he referred to
probably because the rendering and change is so close.

In any event I'm saving that link for possible later need- good stuff.

Thanks



From: Registered User on
On Sun, 23 May 2010 08:35:45 -0400, " Cal Who"
<CalWhoNOSPAM(a)roadrunner.com> wrote:

>
>"Registered User" <n4jvp(a)ix.netcom.com> wrote in message
>news:42qhv51mlka86p7547o6qo2j48nfmcf78t(a)4ax.com...
>> On Sat, 22 May 2010 20:34:51 -0400, " Cal Who"
>> <CalWhoNOSPAM(a)roadrunner.com> wrote:
>>
>>>
>>>"Registered User" <n4jvp(a)ix.netcom.com> wrote in message
>>>news:rbogv5p4i6uotm8qgsr8ajok5b1jhvdd4s(a)4ax.com...
>>>> On Sat, 22 May 2010 18:19:25 -0400, " Cal Who"
>>>> <CalWhoNOSPAM(a)roadrunner.com> wrote:
>>>>
>>>>>That's what I thought but lost confidence when it returned null in the
>>>>>following:
>>>>>
>>>>><script type="text/javascript">
>>>>>
>>>>>function SetMargins(id) {
>>>>>
>>>>>var element = document.getElementById(id);
>>>>>
>>>>>...
>>>>>
>>>>>Which is in the .master and the id looks like I'd expect:
>>>>>
>>>>>id = "ctl00_BottomImageCPH_QQQ"
>>>>>
>>>>>
>>>>>
>>>>>I called it from and aspx.vb file
>>>>>
>>>>><asp:Content ID="Content8" runat="server"
>>>>>ContentPlaceHolderID="BottomImageCPH">
>>>>>
>>>>><script type="text/javascript">
>>>>>
>>>>>SetMargins('<%=QQQ.ClientID%>');
>>>>>
>>>>></script>
>>>>>
>>>>>
>>>>><div runat="server" id="QQQ" style="margin-left: 10%; margin-right:
>>>>>10%;"
>>>>> >
>>>>>
>>>>>...
>>>>>
>>>>>
>>>>>Why the null??
>>>>>
>>>> From the second snippet it appears the SetMargins method is being
>>>> called as the document is rendered. The document is rendered from top
>>>> to bottom. If SetMargins is called before control QQQ is rendered to
>>>> the document, the document won't find the control, and
>>>> document.getElementById will return null.
>>>I bet that is why IE8 developer tool only shows the HTML to just befor
>>>QQQ.
>>>That's as much as was rendered.
>>>
>>>
>>>>
>>>> You may have to read that last sentence a couple of times ;)
>>>>
>>>> I would suggest attaching a javascript method to the page body's
>>>> onload event. That method will be called after the page has been
>>>> rendered. From within that method make the call to SetMargins.
>>>
>>>But there are no events in a content page, is there?
>>>
>> This is true but a solution can be found at
>> http://www.webreference.com/programming/javascript/onloads/
>>
>> regards
>> A.G.
>
>I moved the call to right after the </div> and that seems to have fixed it.
>I'm not sure if that is a reliable way.
>
>Do you think adding an event would be more reliable (say over different
>browser types)
>
I would use the onload event because the page has been loaded. Leaving
the call in-line with the rendering works but is subject to error if
the mark-up gets re-arranged by someone else. AFAIK all browsers
support the onload event so that should not be an issue.

>In this situation I don't see the "magically change" he referred to
>probably because the rendering and change is so close.
>
If the user could see the change there wouldn't be any magic ;)

>In any event I'm saving that link for possible later need- good stuff.
>

regards
A.G.