PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 1.00 average.

accessing runat=server div in javascript

 
 
baldrick
Guest
Posts: n/a
 
      21st Jan 2008
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....

<div id="coordinates" runat=server></div>

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



<script language="javascript" type="text/javascript">
// this writes coordinates to a cookie
function Polygon_Client(){

var element = document.getElementById("coordinates");
if (element) {
document.cookie = "coordinates=" +
document.getElementById("coordinates").innerHTML;
}
else
{
alert('javascript cant find div coordinates');
}
return true;
}
</script>
 
Reply With Quote
 
 
 
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      21st Jan 2008
"baldrick" <(E-Mail Removed)> wrote in message
news:6fa09afe-782c-4548-8e04-(E-Mail Removed)...

> 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

 
Reply With Quote
 
Scott Roberts
Guest
Posts: n/a
 
      21st Jan 2008
> 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 ;

 
Reply With Quote
 
Scott Roberts
Guest
Posts: n/a
 
      21st Jan 2008

"Mark Rae [MVP]" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> "baldrick" <(E-Mail Removed)> wrote in message
> news:6fa09afe-782c-4548-8e04-(E-Mail Removed)...
>
>> 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?

 
Reply With Quote
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      21st Jan 2008
"Scott Roberts" <(E-Mail Removed)> wrote in
message news:(E-Mail Removed)...

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

 
Reply With Quote
 
Scott Roberts
Guest
Posts: n/a
 
      21st Jan 2008

"Mark Rae [MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "Scott Roberts" <(E-Mail Removed)> wrote in
> message news:(E-Mail Removed)...
>
>>>> 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.

 
Reply With Quote
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      22nd Jan 2008
"Scott Roberts" <(E-Mail Removed)> wrote in
message news:%23Vu%(E-Mail Removed)...

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

 
Reply With Quote
 
baldrick
Guest
Posts: n/a
 
      22nd Jan 2008
OK forget the cookie thing. The real issue is this

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

<div id="coordinates" ></div>

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

<div id="coordinates" runat=server></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.

Thanks in advance

Phil









On Jan 22, 7:59*am, baldrick <philbrier...@hotmail.com> 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=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....
>
> <div id="coordinates" runat=server></div>
>
> Me.MasterPageForm.Attributes.Add("onsubmit", "javascript: return
> Polygon_Client();")
>
> *<script language="javascript" type="text/javascript">
> * * * * // this writes coordinates to a cookie
> * * * * function Polygon_Client(){
>
> * * * * * *var element = document.getElementById("coordinates");
> * * * * * * if (element) {
> * * * * * * * * * * * * document.cookie = "coordinates=" +
> document.getElementById("coordinates").innerHTML;
> * * * * * * * * * * * * * * * * *}
> * * * * * * else
> * * * * * * {
> * * * * * * alert('javascript cant find div coordinates');
> * * * * * * }
> * * * * * * * return true;
> * * * * }
> * </script>


 
Reply With Quote
 
Scott Roberts
Guest
Posts: n/a
 
      22nd Jan 2008

"baldrick" <(E-Mail Removed)> wrote in message
news:fe9d83ef-834a-4f1c-997b-(E-Mail Removed)...
> OK forget the cookie thing. The real issue is this
>
> I have a div in an asp.net page as below
>
> <div id="coordinates" ></div>
>
> 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
>
> <div id="coordinates" runat=server></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.

 
Reply With Quote
 
baldrick
Guest
Posts: n/a
 
      22nd Jan 2008
On Jan 22, 3:30*pm, "Scott Roberts" <srobe...@no.spam.here-webworks-
software.com> wrote:
> "baldrick" <philbrier...@hotmail.com> wrote in message
>
> news:fe9d83ef-834a-4f1c-997b-(E-Mail Removed)...
>
>
>
>
>
> > OK forget the cookie thing. The real issue is this

>
> > I have adivin an asp.net page as below

>
> > <divid="coordinates" ></div>

>
> > 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 = something *;

>
> > This all works fine until I add the runat=server to thediv

>
> > <divid="coordinates" runat=server></div>

>
> > 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=server, 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("<%= 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 thedivwhen
> 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!
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Javascript and controls with runat=server? Erland Microsoft ASP .NET 4 14th Oct 2006 11:48 PM
JavaScript vs runat=server problem Tina Microsoft ASP .NET 3 30th May 2006 11:24 PM
Client-Side JavaScript Problem in runat=server "<SELECT>" =?Utf-8?B?QWxleCBNYWdoZW4=?= Microsoft ASP .NET 7 1st May 2006 01:11 PM
Accessing server controls using javascript... Stu Microsoft ASP .NET 2 20th Mar 2006 07:10 PM
Re: Is it possible to call Javascript's window close() from <SCRIPT RUNAT="SERVER">? Kevin Spencer Microsoft ASP .NET 0 15th Jul 2003 01:59 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:10 PM.