migrating Document.Write to Code Behind

Discussion in 'ASP .Net' started by Jeronimo Bertran, Nov 13, 2003.

  1. 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
     
    Jeronimo Bertran, Nov 13, 2003
    #1
    1. Advertising

  2. 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.
     
    Jacob Yang [MSFT], Nov 14, 2003
    #2
    1. Advertising

  3. 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
     
    Jeronimo Bertran, Nov 14, 2003
    #3
  4. Jeronimo Bertran

    alex bowers Guest

    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
    >-----Original Message-----
    >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
    >.
    >
     
    alex bowers, Nov 14, 2003
    #4
  5. Sure. All you have to do is dynamically build your tag.

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    ..Net Developer
    http://www.takempis.com
    Big Things are made up of
    Lots of Little Things.

    "Jeronimo Bertran" <> wrote in message
    news:Xns9432DC7D366EDjeronimobertrancom@207.46.248.16...
    > 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
     
    Kevin Spencer, Nov 14, 2003
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben Miller [msft]

    Re: Code Behind vs. no code behind: error

    Ben Miller [msft], Jun 27, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    644
    Alphonse Giambrone
    Jun 28, 2003
  2. Daniel Manes

    Code-Behind Pain in the Behind!

    Daniel Manes, Jun 10, 2005, in forum: ASP .Net
    Replies:
    11
    Views:
    709
  3. John

    Non-code behind to code behind

    John, Feb 19, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    529
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Feb 19, 2007
  4. jullag
    Replies:
    20
    Views:
    339
    Frances
    Sep 22, 2005
  5. Frank Peterson
    Replies:
    9
    Views:
    245
    David Mark
    Jun 28, 2009
Loading...

Share This Page