From: Cal Who on

"Mark Rae [MVP]" <mark(a)markrae.net> wrote in message
news:D114E876-E170-4A90-B9D2-4CA8A33B6C97(a)microsoft.com...
>" Cal Who" <CalWhoNOSPAM(a)roadrunner.com> wrote in message
>news:ht9l9g$dti$1(a)news.eternal-september.org...
>
>> Why the null??
>
> Because of ASP.NET's control ID munging.
>
> var control = document getElementById('<%=MyControl.ClientID%>');
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net
Help me out here. It seems to me that
calling it from the .vb file using the clientId
is effectively the same.
And the munged string gets passed.

No?

As ways, Thanks


From: Cal Who on

"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?

>
> regards
> A.G.


Thanks


From: Mark Rae [MVP] on
" Cal Who" <CalWhoNOSPAM(a)roadrunner.com> wrote in message
news:ht9sv9$cdh$1(a)news.eternal-september.org...

> No?

Yes, but it seems from other replies that you're trying to call the
SetMargins function before the page is completely rendered, which is why
it's not finding the control...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

From: Registered User on
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.
From: Cal Who on

"Mark Rae [MVP]" <mark(a)markrae.net> wrote in message
news:00C8F499-75A3-4B97-BDB1-43ED2355537B(a)microsoft.com...
>" Cal Who" <CalWhoNOSPAM(a)roadrunner.com> wrote in message
>news:ht9sv9$cdh$1(a)news.eternal-september.org...
>
>> No?
>
> Yes, but it seems from other replies that you're trying to call the
> SetMargins function before the page is completely rendered, which is why
> it's not finding the control...
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net
True, I just move the call to after the </div> and that seems to have fixed
it. I'm not sure if that is a reliable way.

Thanks