migrating Document.Write to Code Behind

J

Jeronimo Bertran

This may be a very simple question.

I have some old java code that uses scripting to dynamically create a <MAP>
in my HTML.


<map name="Map">
<script>
var i;
for (i=0; i<arr.length; i++)
{
document.write("<area onmouseover='OnMouseOver(" + i + ")'
href='javascript:ShowDetails(" + arr.Id + ")' shape=circle coords='" +
arr.X + "," + arr.Y + ",5'>\r\n");
}

</script>
</map>


I am now converting this code to C# and trying to use Code Behind. How can
I achieve the same result?

Thanks

Jeronimo
 
J

Jacob Yang [MSFT]

Hi Jeronimo,

As I understand, what you really need is emit client-side script blocks in
the server side. We can use the Page.RegisterStartupScript Method. Please
refer to the following URL for the detailed information and code snippet.

Page.RegisterStartupScript Method
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemwebuipageclassregisterstartupscripttopic.asp

Does it answer your question? If I have misunderstood your concern, please
feel free to let me know.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
J

Jeronimo Bertran

Hi Jacob

After re-reading my question I realized how poorly I had described it.
Here's another shot:

I need to create a map object dynamically. The number of areas in the map
is variable and needs to be created dynamically.

example:

<img src="Img/map01.gif" border="0" usemap="#Map">
<map name="Map">
<area onmouseover="OnMouseOver(0)" href="javascript:void(0)" shape=circle
coords='10,20,5'>

<area onmouseover="OnMouseOver(1)" href="javascript:void(0)" shape=circle
coords='40,33,5'>
</map>


My question is, if I create a WebControl that includes an image object and
create the image programatically by using the HtmlImage class, is their a
way to create the map object and assign it to the image?

Thanks!!
Jeronimo
 
A

alex bowers

Jeronimo,
Creating the map dynamically can be done on the server
either by designing a custom control that renders html as
you wish, or by adding the script using one of the
Page.RegisterScript methods as Jacob suggests.
You can assign the map to the image on the server by
accessing the image's attributes collection. eg
Image1.Attributes.Add("usemap","#Map").

Hope this helps you.

alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top