Create String

Discussion in 'ASP .Net' started by shapper, Oct 19, 2007.

  1. shapper

    shapper Guest

    Hello,

    I need to create the following string at runtime to add to my page:

    "
    <script type="text/javascript"><!--
    client = "3894758346587";
    width = 800;
    height = 600;
    format = "image";
    FirstWord; SecondWord
    name = "1213131+6456456";
    //-->
    </script>
    "

    The values client, width, height, format, FirstWord, SecondWord, name
    are taken from properties with the same name: Me.Client, Me.Width, ...

    What is the best way to build this string.

    Note that if, for example, Me.Client is empty then the code line
    'client="3894758346587";' should not be added.

    Thanks,
    Thanks
    shapper, Oct 19, 2007
    #1
    1. Advertising

  2. shapper wrote:
    > Hello,
    >
    > I need to create the following string at runtime to add to my page:
    >
    > "
    > <script type="text/javascript"><!--
    > client = "3894758346587";
    > width = 800;
    > height = 600;
    > format = "image";
    > FirstWord; SecondWord
    > name = "1213131+6456456";
    > //-->
    > </script>
    > "
    >
    > The values client, width, height, format, FirstWord, SecondWord, name
    > are taken from properties with the same name: Me.Client, Me.Width, ...
    >
    > What is the best way to build this string.
    >
    > Note that if, for example, Me.Client is empty then the code line
    > 'client="3894758346587";' should not be added.
    >
    > Thanks,
    > Thanks
    >


    Use a StringBuilder to create the string, then the
    ClientScript.RegisterStartupScript method to add it to the page.

    You can make the RegisterStartupScript method add the script tag, so
    don't put that in the string, just the Javascript code.

    --
    Göran Andersson
    _____
    http://www.guffa.com
    =?ISO-8859-1?Q?G=F6ran_Andersson?=, Oct 19, 2007
    #2
    1. Advertising

  3. shapper

    bruce barker Guest

    you could get more object oriented and use a JSON serializer.

    -- bruce

    shapper wrote:
    > Hello,
    >
    > I need to create the following string at runtime to add to my page:
    >
    > "
    > <script type="text/javascript"><!--
    > client = "3894758346587";
    > width = 800;
    > height = 600;
    > format = "image";
    > FirstWord; SecondWord
    > name = "1213131+6456456";
    > //-->
    > </script>
    > "
    >
    > The values client, width, height, format, FirstWord, SecondWord, name
    > are taken from properties with the same name: Me.Client, Me.Width, ...
    >
    > What is the best way to build this string.
    >
    > Note that if, for example, Me.Client is empty then the code line
    > 'client="3894758346587";' should not be added.
    >
    > Thanks,
    > Thanks
    >
    bruce barker, Oct 19, 2007
    #3
    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. Hessam
    Replies:
    0
    Views:
    2,166
    Hessam
    Aug 8, 2003
  2. ohaya
    Replies:
    5
    Views:
    13,230
    Roedy Green
    Oct 19, 2005
  3. Sonu
    Replies:
    1
    Views:
    792
  4. Hessam
    Replies:
    1
    Views:
    221
    Teemu Keiski
    Aug 16, 2003
  5. Hessam
    Replies:
    0
    Views:
    261
    Hessam
    Aug 8, 2003
Loading...

Share This Page