accessing runat=server div in javascript

accessing runat=server div in javascript

am 21.01.2008 21:59:50 von philbrierley

Hi,

I have a div on my page as below and want to write the content of the
div to a cookie so information can be passed between two differnet
pages. With the runat=server I find that the div is not visible to the
rest of page as I get the cant 'find div message'.

The application works fine without the runat=server, but I need to be
able to store the contents of the div in a databse for later recall,
hence need the runat=server.

I also need the div to be accessible by the second page as it directly
reads the content using javascript...

parent.document.getElementById("coordinates").innerHTML = html ;


Does anyone have any simple solution or workaround as to how I can
keep the div accessible to javascript but also be able to keep the
runat=server bit?

Regards,
Phil

Code snippets....



Me.MasterPageForm.Attributes.Add("onsubmit", "javascript: return
Polygon_Client();")



Re: accessing runat=server div in javascript

am 21.01.2008 22:05:59 von mark

"baldrick" wrote in message
news:6fa09afe-782c-4548-8e04-374d1fe1df32@q77g2000hsh.google groups.com...

> I have a div on my page as below and want to write the content of the
> div to a cookie so information can be passed between two differnet
> pages.
>
> Does anyone have any simple solution or workaround

Yep - don't use cookies to persist state between pages - use Session
instead. That's what it's for...


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

Re: accessing runat=server div in javascript

am 21.01.2008 22:59:45 von Scott Roberts

> I have a div on my page as below and want to write the content of the
> div to a cookie so information can be passed between two differnet
> pages. With the runat=server I find that the div is not visible to the
> rest of page as I get the cant 'find div message'.
>
> The application works fine without the runat=server, but I need to be
> able to store the contents of the div in a databse for later recall,
> hence need the runat=server.

When you add "runat=server" the control becomes a server control and is
subject to the naming convention of server controls. If you look at the html
source of your page, you'll notice that the control is not named
"coordinates" anymore.

> I also need the div to be accessible by the second page as it directly
> reads the content using javascript...
>
> parent.document.getElementById("coordinates").innerHTML = html ;
>
>
> Does anyone have any simple solution or workaround as to how I can
> keep the div accessible to javascript but also be able to keep the
> runat=server bit?

Try this:

parent.document.getElementById("<%= coordinates.ClientID %>").innerHTML =
html ;

Re: accessing runat=server div in javascript

am 21.01.2008 23:00:31 von Scott Roberts

"Mark Rae [MVP]" wrote in message
news:%23BU9xFHXIHA.5348@TK2MSFTNGP03.phx.gbl...
> "baldrick" wrote in message
> news:6fa09afe-782c-4548-8e04-374d1fe1df32@q77g2000hsh.google groups.com...
>
>> I have a div on my page as below and want to write the content of the
>> div to a cookie so information can be passed between two differnet
>> pages.
>>
>> Does anyone have any simple solution or workaround
>
> Yep - don't use cookies to persist state between pages - use Session
> instead. That's what it's for...


What are cookies for?

Re: accessing runat=server div in javascript

am 21.01.2008 23:04:20 von mark

"Scott Roberts" wrote in
message news:Ofm4KkHXIHA.2268@TK2MSFTNGP02.phx.gbl...

>>> Does anyone have any simple solution or workaround
>>
>> Yep - don't use cookies to persist state between pages - use Session
>> instead. That's what it's for...
>
> What are cookies for?


Persisting data between visits to the same site...


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

Re: accessing runat=server div in javascript

am 21.01.2008 23:23:10 von Scott Roberts

"Mark Rae [MVP]" wrote in message
news:Oc2qYmHXIHA.1208@TK2MSFTNGP05.phx.gbl...
> "Scott Roberts" wrote in
> message news:Ofm4KkHXIHA.2268@TK2MSFTNGP02.phx.gbl...
>
>>>> Does anyone have any simple solution or workaround
>>>
>>> Yep - don't use cookies to persist state between pages - use Session
>>> instead. That's what it's for...
>>
>> What are cookies for?
>
>
> Persisting data between visits to the same site...

Do you consider a postback that occurs 8 hours after the initial page-load
to be another "visit"?

I guess I shouldn't beat around the bush. There are situations where using
cookies is preferable (even necessary) for persisting data between pages
(long delays between postbacks, redirects to another virtual directory,
etc.). Whether the OPs situation is one of those is unclear, as he didn't
provide enough information.

Re: accessing runat=server div in javascript

am 22.01.2008 01:20:59 von mark

"Scott Roberts" wrote in
message news:%23Vu%230wHXIHA.1204@TK2MSFTNGP03.phx.gbl...

>>> What are cookies for?
>>
>> Persisting data between visits to the same site...
>
> Do you consider a postback that occurs 8 hours after the initial page-load
> to be another "visit"?


If you need to persist data for longer than the duration of session, then
you need to use a cookie...


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

Re: accessing runat=server div in javascript

am 22.01.2008 04:59:29 von philbrierley

OK forget the cookie thing. The real issue is this

I have a div in an asp.net page as below



Within this page I have an inline frame that contains another page
that is NOT an asp.net page. It is just a page full of javascript.

I can do things on this second page that that that change the content
of the div on the ASP page quite easily using the javascript...

parent.document.getElementById("coordinates").innerHTML =3D something ;

This all works fine until I add the runat=3Dserver to the div



I need to add this as the content of the div now also needs to be able
to be filled from a database using the asp.net page. The problem now
is that by adding the runat=3Dserver, my second page in the inline frame
cannot now change the parent page as the div is no longer recognised.

I suspect there is a simple solution or workaround. I would appreciate
any useful suggestions.

Thanks in advance

Phil









On Jan 22, 7:59=A0am, baldrick wrote:
> Hi,
>
> I have a div on my page as below and want to write the content of the
> div to a cookie so information can be passed between two differnet
> pages. With the runat=3Dserver I find that the div is not visible to the
> rest of page as I get the cant 'find div message'.
>
> The application works fine without the runat=3Dserver, but I need to be
> able to store the contents of the div in a databse for later recall,
> hence need the runat=3Dserver.
>
> I also need the div to be accessible by the second page as it directly
> reads the content using javascript...
>
> =A0parent.document.getElementById("coordinates").innerHTML =3D html ;
>
> Does anyone have any simple solution or workaround as to how I can
> keep the div accessible to javascript but also be able to keep the
> runat=3Dserver bit?
>
> Regards,
> Phil
>
> Code snippets....
>
>

>
> Me.MasterPageForm.Attributes.Add("onsubmit", "javascript: return
> Polygon_Client();")
>
> =A0

Re: accessing runat=server div in javascript

am 22.01.2008 05:30:23 von Scott Roberts

"baldrick" wrote in message
news:fe9d83ef-834a-4f1c-997b-10bb5ed555fb@s19g2000prg.google groups.com...
> OK forget the cookie thing. The real issue is this
>
> I have a div in an asp.net page as below
>
>


>
> Within this page I have an inline frame that contains another page
> that is NOT an asp.net page. It is just a page full of javascript.
>
> I can do things on this second page that that that change the content
> of the div on the ASP page quite easily using the javascript...
>
> parent.document.getElementById("coordinates").innerHTML = something ;
>
> This all works fine until I add the runat=server to the div
>
>

>
> I need to add this as the content of the div now also needs to be able
> to be filled from a database using the asp.net page. The problem now
> is that by adding the runat=server, my second page in the inline frame
> cannot now change the parent page as the div is no longer recognised.
>
> I suspect there is a simple solution or workaround. I would appreciate
> any useful suggestions.

There is. Did you see my other post?

Try this:

parent.document.getElementById("<%= coordinates.ClientId %>").innerHTML =
something ;


Oh, never mind, your inner page is not aspx. The problem is, when you add
"runat=server" then a different "name" attribute is assigned to the div when
the html is rendered. I'm not sure that there is a way around that. You
might try something along the lines of adding a non-server div inside a
server div, or vice-versa.

Re: accessing runat=server div in javascript

am 22.01.2008 06:12:47 von philbrierley

On Jan 22, 3:30=A0pm, "Scott Roberts" software.com> wrote:
> "baldrick" wrote in message
>
> news:fe9d83ef-834a-4f1c-997b-10bb5ed555fb@s19g2000prg.google groups.com...
>
>
>
>
>
> > OK forget the cookie thing. The real issue is this
>
> > I have adivin an asp.net page as below
>
> >
>
> > Within this page I have an inline frame that contains another page
> > that is NOT an asp.net page. It is just a page full of javascript.
>
> > I can do things on this second page that that that change thecontent
> > of thedivon the ASP page quite easily using the javascript...
>
> > parent.document.getElementById("coordinates").innerHTML =3D something =
=A0;
>
> > This all works fine until I add the runat=3Dserver to thediv
>
> >
>
> > I need to add this as thecontentof thedivnow also needs to be able
> > to be filled from a database using the asp.net page. The problem now
> > is that by adding the runat=3Dserver, my second page in the inline frame=

> > cannot now change the parent page as thedivis no longer recognised.
>
> > I suspect there is a simple solution or workaround. I would appreciate
> > any useful suggestions.
>
> There is. Did you see my other post?
>
> Try this:
>
> parent.document.getElementById("<%=3D coordinates.ClientId %>").innerHTML =
=3D
> something =A0;
>
> Oh, never mind, your inner page is not aspx. The problem is, when you add
> "runat=3Dserver" then a different "name" attribute is assigned to thedivwh=
en
> the html is rendered. I'm not sure that there is a way around that. You
> might try something along the lines of adding a non-serverdivinside a
> serverdiv, or vice-versa.- Hide quoted text -
>
> - Show quoted text -

Yes - just trying that now!

Re: accessing runat=server div in javascript

am 22.01.2008 09:13:31 von Nick Chan

most probably, asp.net changes the id=3D"coordinates" to something else

u can do something like this



javascript :

var o =3D parent.document.getElementById('coordinates')
while(o.tagName!=3D'DIV')
o=3Do.nextSibling

o.innerHTML =3D 'something'


On Jan 22, 11:59=A0am, baldrick wrote:
> OK forget the cookie thing. The real issue is this
>
> I have a div in an asp.net page as below
>
>

>
> Within this page I have an inline frame that contains another page
> that is NOT an asp.net page. It is just a page full of javascript.
>
> I can do things on this second page that that that change the content
> of the div on the ASP page quite easily using the javascript...
>
> parent.document.getElementById("coordinates").innerHTML =3D something =A0;=

>
> This all works fine until I add the runat=3Dserver to the div
>
>

>
> I need to add this as the content of the div now also needs to be able
> to be filled from a database using the asp.net page. The problem now
> is that by adding the runat=3Dserver, my second page in the inline frame
> cannot now change the parent page as the div is no longer recognised.
>
> I suspect there is a simple solution or workaround. I would appreciate
> any useful suggestions.
>
> Thanks in advance
>
> Phil
>
> On Jan 22, 7:59=A0am, baldrick wrote:
>
> > Hi,
>
> > I have a div on my page as below and want to write the content of the
> > div to a cookie so information can be passed between two differnet
> > pages. With the runat=3Dserver I find that the div is not visible to the=

> > rest of page as I get the cant 'find div message'.
>
> > The application works fine without the runat=3Dserver, but I need to be
> > able to store the contents of the div in a databse for later recall,
> > hence need the runat=3Dserver.
>
> > I also need the div to be accessible by the second page as it directly
> > reads the content using javascript...
>
> > =A0parent.document.getElementById("coordinates").innerHTML =3D html ;
>
> > Does anyone have any simple solution or workaround as to how I can
> > keep the div accessible to javascript but also be able to keep the
> > runat=3Dserver bit?
>
> > Regards,
> > Phil
>
> > Code snippets....
>
> >

>
> > Me.MasterPageForm.Attributes.Add("onsubmit", "javascript: return
> > Polygon_Client();")
>
> > =A0