writing asp variabls within javascript blocks

Discussion in 'ASP .Net' started by Darrel, May 24, 2006.

  1. Darrel

    Darrel Guest

    In asp.net 1.1, what is the proper method for writing variables to the aspx
    page that are contained within javascript blocks?

    example:

    <script language="JavaScript">
    myJavascriptVariable= <asp:Literal Runat="server"
    ID="ltl_sectionsJavascriptVariables"></asp:Literal>;
    </script>

    ASP.net doesn't like that syntax.

    -Darrel
     
    Darrel, May 24, 2006
    #1
    1. Advertisements

  2. Patrick.O.Ige, May 24, 2006
    #2
    1. Advertisements

  3. Darrel

    Darrel Guest

    RegisterClientScriptBlock & RegisterStartupScript
    Well, that's a pain. Isn't javascript supposed to be client side? Why stick
    it in the codebehind?

    Thanks, though!

    -Darrel
     
    Darrel, May 24, 2006
    #3
  4. Darrel

    MS Guest

    hi

    use this way ....

    <script language="JavaScript">
    myJavascriptVariable= <% = serverVariable %>;
    </script>

    Thanks
    Munawar
     
    MS, May 26, 2006
    #4
  5. Hi,
    I don't get your question.

    JavaScript is client-side, but some part of your scripts might depend on
    server-side variables. What I do is create JS files with the "pure
    client-side code". However, some parts of the code must be created
    dynamically on the server (typical example: localized texts), so I add
    script lines using RegisterClientScriptBlock.

    Eventually, every piece of script added to the page is interpreted and
    can be referenced from other piece of script on the same page.

    HTH,
    Laurent
     
    Laurent Bugnion, May 28, 2006
    #5
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.